ios - Passing Textfield Value to Label in another view Programmatically -


i newbie in iphone development , xcode. , having hard time running simple demo app passing textfield text 1 view label in view programmatically.... , dont know going wrong [even did nslog check string coming...it says null :( ]

see if guys can me find lacking code?? in advance!

here thing did:

#import <uikit/uikit.h>   @interface viewcontroller : uiviewcontroller<uitextfielddelegate>{     nsstring *str;  } @property(nonatomic,retain)nsstring *str;  @end 

viewcontroller.m *


#import "viewcontroller.h" #import "nextviewcontroller.h"  @interface viewcontroller ()  @end  @implementation viewcontroller @synthesize str;  - (void)viewdidload {      uitextfield *txt =[[uitextfield alloc]initwithframe:cgrectmake(40, 40, 200, 30)];     txt.borderstyle = uitextborderstyleroundedrect ;     txt.delegate=self;     [self.view addsubview:txt];       uibutton *btn=[uibutton buttonwithtype:uibuttontyperoundedrect];     btn.frame = cgrectmake(80, 80, 200, 30);     [btn settitle:@"press" forstate:uicontrolstatenormal];     [btn addtarget:self action:@selector(btn:) forcontrolevents:uicontroleventtouchupinside];     [self.view addsubview:btn];      [super viewdidload]; }  - (bool)textfieldshouldendediting:(uitextfield *)textfield{     self.str = [textfield text];     return yes; }  -(ibaction)btn:(id)sender{        nextviewcontroller *next =[[nextviewcontroller alloc]init];  [self.navigationcontroller pushviewcontroller:next animated:yes];  } 

nextviewcontroller.h *


#import <uikit/uikit.h> #import "viewcontroller.h"  @interface nextviewcontroller : uiviewcontroller{     nsstring *str; }     @property(nonatomic,retain)nsstring *str;  @end 

nextviewcontroller.m *


#import "nextviewcontroller.h" #import "viewcontroller.h"  @interface nextviewcontroller ()  @end  @implementation nextviewcontroller @synthesize str; - (void)viewdidload {     uilabel *lbl = [[uilabel alloc]init];     lbl.frame=cgrectmake(40, 40, 200, 30);     viewcontroller *vc =[[viewcontroller alloc]init];     lbl.text=vc.str;`enter code here`      [self.view addsubview:lbl];     [super viewdidload]; } 

you not setting nextviewcontroller's property of str string you'd set to.

-(ibaction)btn:(id)sender{     nextviewcontroller *next =[[nextviewcontroller alloc]init];     if (self.str)         next.str = self.str;     [self.navigationcontroller pushviewcontroller:next animated:yes]; } 

also, creating new instance of viewcontroller no apparent reason. use following sets string passed nextviewcontroller label:

lbl.text = self.str; 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -