How to create a new line by tapping the return key in UITextView ios -



How to create a new line by tapping the return key in UITextView ios -

i newly iphone. have added 1 uitextview using xib in application, after tapping on done key it's resigning keyboard. but, want create new line tapping it, means should go next paragraph. please help me accomplish output. here code :

- (void)textviewdidendediting:(uitextview *)textview1 { if (![textview1 hastext]) { [textview1 addsubview:placeholderlabel]; } else{ nslog(@"done button clicked!!"); } cgrect rect; if(screenbounds.size.height == 568)//iphone5 { rect = cgrectmake(5, 76, 310, 491); } else{ if(_kisios7){ rect = cgrectmake(5, 76, 310, 404); } else{ rect = cgrectmake(0, 44, 320, 436); } } [uiview beginanimations:nil context:null]; [uiview setanimationduration:0.3]; txtview.frame = rect; [uiview commitanimations]; } - (bool)textview:(uitextview *)textview shouldchangetextinrange:(nsrange)range replacementtext:(nsstring *)text { if (range.length == 0) { if ([text isequaltostring:@"\n"]) { [textview resignfirstresponder]; homecoming no; } } homecoming yes; }

thanks in advance.

you should implement delegate method returning value no (so on tapping "return" or "done" not close keyboard).

- (bool)textviewshouldendediting:(uitextview *)textview { homecoming no; }

and remove or alter logic of next lines of code:

if (range.length == 0) { if ([text isequaltostring:@"\n"]) { [textview resignfirstresponder]; homecoming no; } }

so in textviewshouldendediting can determine/calculate situations when need close keyboard (if want close - homecoming yes, otherwise homecoming - no)

you can alter logic of

(bool)textview:(uitextview *)textview shouldchangetextinrange:(nsrange)range replacementtext:(nsstring *)text {

to

if (range.length == 0) { if ([text isequaltostring:@"\n"]) { textview.text = [nsstring stringwithformat:@"%@\n\t",textview.text]; homecoming no; } }

in case when user tap on action button on keyboard (like "return"). textview insert new line , additional tab in text.

i hope help you.

ios uitextview uitextviewdelegate

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -