ios - How to pass value in uitextview using segue -
i'm trying create in uitextview every time text encounter kind of symbol "@". text after symbol send other controller.
here's code
- (bool)textview:(uitextview *)atextview shouldchangetextinrange:(nsrange)range replacementtext:(nsstring *)text { // "length of existing text" - "length of replaced text" + "length of replacement text" nsinteger newtextlength = [self.addingtext.text length] - range.length + [text length]; if([text isequaltostring:@"@"] || secondstring){ secondstring = true; nsstring * stringtorange = [self.addingtext.text substringwithrange:nsmakerange(0,range.location)]; // appending typed charactor stringtorange = [stringtorange stringbyappendingstring:text]; // processing last typed word nsarray *wordarray = [stringtorange componentsseparatedbystring:@"@"]; self.getsecondstring = [wordarray lastobject]; // wordtyped give last typed object nslog(@"\nwordtyped : %@",self.getsecondstring); } if (newtextlength > 50) { // don't allow change [atextview resignfirstresponder]; return no; } self.countchar.text = [nsstring stringwithformat:@"%li", (long)newtextlength]; return yes; }
i code here. work when use nslog time click button send other controller using segue. show null value. hoping here. in advance
here's button code
- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { cameraviewcontroller * cameraviewcontroller = (cameraviewcontroller *)[segue destinationviewcontroller]; if([segue.identifier isequaltostring:@"createtext"]){ nslog(@"prepareforsegue: %@ == %@", self.addingtext.text,self.getsecondstring); cameraviewcontroller.inputcreatetext = [nsstring stringwithformat:@"%@", self.addingtext.text]; cameraviewcontroller.secondinputcreatetext =[nsstring stringwithformat:@"%@", self.getsecondstring]; } }
i think problem modifying string inside textview:shouldchangetextinrange:
gets called every typed in character. if purpose send string after @
on tap on button calculation on button handler or inside prepareforsegue:sender:
. if reason want stick own implementation advise put targeted string inside nsmutablearray
property created @ class level don't loose data. , can combine string inside array [arrayofstrings componentsjoinedbystring:@" "]
.
Comments
Post a Comment