iphone - Nsstring data isnt retianed after passing a controller -
my nsstring data being lost when transfer view controller 1 view controller 2 viewcontroller 3. when transfer viewcontroller 1 viewcontroller 3 works. way switching viewcontroller 1 view controller 2 causing me lose nsstring data reason. post code below, guess need in view controller 2.
viewcontroller1
-(void)button{ stringentered=textfield.text; viewcontroller2 *vc2 = [[viewcontroller3 alloc] init]; vc2.string = [[nsstring stringwithstring:textfield.text] retain]; [self.navigationcontroller pushviewcontroller:vc2 animated:yes]; }
viewcontroller 2
-(void)button{ viewcontroller3 *vc3 = [[viewcontroller3 alloc] init]; [self.navigationcontroller pushviewcontroller:vc3 animated:yes]; }
viewcontroller3
nsstring *emailbody = [nsstring stringwithformat:@"%@",string];
in viewcontroller 3 .h file write below line
@property(retain,nonatomic)nsstring *string;
and synthesize in .m file
@synthesize string;
now in viewcontroller 2
-(void)button{ viewcontroller3 *vc3 = [[viewcontroller3 alloc] init]; vc3.string =string; [self.navigationcontroller pushviewcontroller:vc3 animated:yes]; }
make sure have define string in vc2 properly.
Comments
Post a Comment