objective c - Can't change UILabel's text from another View Controller -
objective c - Can't change UILabel's text from another View Controller -
i have 2 view controllers, 1 text field , 'next' button , 1 label. thought fill in name in text field , click 'next'. should switch other view , label should show name.
when switch views however, label empty. rather new objective-c , i'm hoping knows why happening :).
viewcontroller.m:
@interface viewcontroller () { iboutlet uilabel *label; iboutlet uitextfield *textfield; } -(ibaction)go:(id)sender { label.text = textfield.text; } -(ibaction)remove:(id)sender { [sender resignfirstresponder]; }
you said have 2 view controllers. first view controller has instance of uitextfield, , uibutton. sec view controller has instance of uilabel.
however, noticed in code viewcontroller.m, assuming first view controller, has 2 iboutlets, 1 uilabel , 1 uitextfield, doesn't create sense because uilabel supposed part of sec view controller.
what need delete iboutlet uilabel first view controller. then, in sec view controller, add together iboutlet it's uilabel.
then, need implement prepareforsegue method in first view controller , add together code statement this:
[[segue destinationviewcontroller]label].text = textfield.text;
this way, when segue performed, pass first view controller's text field's text sec view controller's label.
objective-c xcode xcode5
Comments
Post a Comment