I am stuck on passing data from one ViewController to another. The scenario is as:
I have 2 ViewControllers named : SearchDomainController and LoginViewController. What i am trying to do is pass the string value from SearchDomainController to the UITExtfield in LoginViewController.
In LoginViewController i have declared IBOutlet UITextField *domainField; and also a property @property(nonatomic,retain) UITextField *domainField.
The problem is when i create a new instance of LoginViewController in SearchDomainController and try _loginViewController.domainField.text = @"Some text";
the text never changes in UItextField on LoginViewController.
What did i miss ? And what are the best solution for this kind of problem? Thanx
My guess would be that
_loginViewController.domainFieldis nil at that time, which is probably because the view hasn’t loaded yet, and the label is created when the view loads (via a nib) and not as soon as the view controller object is created.In order to not depend on having the view fully loaded when passing the value, I would have used a separate property for passing along the title, i.e.
_loginViewController.domainFieldText = @"Some text";. Then inviewDidLoadof the_loginViewController, assign the value ofdomaonFieldTextto the actual label.Alternatively, make sure the UILabel instance is created and not nil when you set its text from the other view controller.