ipad - Focus of cursor is not shifting to next UITextView in ios -
this first question on ios
i using 2 uitextview
objects (textview1 , textview2) in view
, each of them has character limit following scenario:
- initially user can enter textview1.
- when entered character limit of textview1 over, cursor automatically shift textview2.
- after building project, if user tap textview2 , try write it, cursor must shifted textview1 (because empty).
i wrote code , works fine except third scenario, user can enter textview1
focus still on textview2
steps reproduce:
- build project
- user tap textview2 first , try write something.
- according written code, focus remain in textview2 user writing textview1 (see attachment)
here snapshot:
here written code:
- (void)viewdidload { [super viewdidload]; [self.textview1 becomefirstresponder]; } - (void)textviewdidchange:(uitextview *)textview{ nsinteger restrictedlengthfortextview1 = 110; nsinteger restrictedlengthfortextview2 = 130; nsstring *temp=textview.text; if(textview == self.textview1){ if([[textview text] length] > restrictedlengthfortextview1){ textview.text=[temp substringtoindex:[temp length]-1]; [textview resignfirstresponder]; [self.textview2 becomefirstresponder]; } }else{ if([[textview text] length] > restrictedlengthfortextview2){ textview.text=[temp substringtoindex:[temp length]-1]; [self.textview2 resignfirstresponder]; } }} - void()textviewdidbeginediting:(uitextview *)textview{ nsinteger restrictedlengthfortextview1 = 110; nslog(@"dalknwdlakwd"); if([[self.textview1 text] length] < restrictedlengthfortextview1){ if(textview == self.textview2){ [self.textview2 resignfirstresponder]; [self.textview1 becomefirstresponder]; } }}
please me here..
please per following:
in .h file
@interface viewcontroller : uiviewcontroller<uitextviewdelegate> { iboutlet uitextview *txtview1; iboutlet uitextview *txtview2; } @end
in .m file
- (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. [txtview1 becomefirstresponder]; txtview2.editable=no; }
implement textview delegate method below:
- (bool)textview:(uitextview *)textview shouldchangetextinrange:(nsrange)range replacementtext:(nsstring *)text { if(textview.tag==1) { if([textview.text length]>25) { txtview2.editable=yes; [txtview2 becomefirstresponder]; } } return yes; }
i have taken text length limit in first textview 24 characters example. hope you.
Comments
Post a Comment