Saturday, 15 May 2010

objective c - Passing String From one View Controller and Displaying it in UITextView in ios -



objective c - Passing String From one View Controller and Displaying it in UITextView in ios -

i have tried every thing solve problem because newbie not getting clear answer. have 2 view controllers. passed info of textview 2nd controller , displaying in uilabel , there no problem it. have send the text of label 1 time again same textview editing. problem when double tap on label navigates me 1st view not displaying text in textview.

-(void)addtexttocanvaswithgesture:(uitextview*)takentext { cgrect rect = cgrectmake(35, 60,takentext.contentsize.width,takentext.contentsize.height); uiview *holderview = [[uiview alloc] initwithframe:rect]; rect.origin.x=0; rect.origin.y=0; uilabel *textlabel=[[uilabel alloc]initwithframe:rect]; [textlabel settext:takentext.text]; self.text=takentext.text; [textlabel settextcolor:takentext.textcolor]; [textlabel setfont:[uifont fontwithname:takentext.font.fontname size:takentext.font.pointsize]]; [textlabel setnumberoflines:0]; [textlabel sizetofit]; [holderview settag:1]; [textlabel settag:1+1]; [holderview addsubview:textlabel]; uitapgesturerecognizer *taprecognizer = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(tapped:)]; [taprecognizer setnumberoftapsrequired:1]; [taprecognizer setdelegate:self]; [holderview addgesturerecognizer:taprecognizer]; taprecognizer = nil; uitapgesturerecognizer *doubletaprecognizer = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(launchtext)]; [doubletaprecognizer setnumberoftapsrequired:2]; [doubletaprecognizer setdelegate:self]; [holderview addgesturerecognizer:doubletaprecognizer]; holderview.userinteractionenabled=yes; [taprecognizer requiregesturerecognizertofail:doubletaprecognizer]; }

i have send label's text textview of 2ndview controller

-(void) launchtext{ [self update:self.text]; [self performseguewithidentifier:@"textadd" sender:self]; } -(void)update:(nsstring*)string{ textaddviewcontroller *txt=[[textaddviewcontroller alloc]init]; txt.usingtext.text=string; }

and fetching string in 2nd view as

-(void)viewdidload { [super viewdidload]; viewcontroller *vm=[[viewcontroller alloc]init]; self.usingtext.text=vm.text; }

override below method in secondviewcontroller, , pass uilabel values firstviewcontroller.

- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { nslog(@"prepareforsegue called"); if ([[segue identifier] isequaltostring:@"controller_segue"]) { textaddviewcontroller *vc = [segue destinationviewcontroller]; [vc.usgingtext settext:@"some text"]; } }

ios objective-c

No comments:

Post a Comment