You cannot set the text to Uitextfield (or any other component like Uilabel or Uitextview) in the method prepareForSegue
, because all the components of the target view controller are not yet allocados (at this point all of them are nil). They will only be allocados when viewController is presented.
It is right to create a Nsstring Property in the target viewController and then set the text of textField with the created Property.
Thus:
In the prepareForSegue
use the following:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqual:@"ViewController2"])
{
ViewController2 *vc2 = [segue destinationViewController];
vc2.myString = self.textField.text;
}
}
and within the target viewController in the method viewDidLoad
:
- (void)viewDidLoad
{
[super viewDidLoad];
(...)
self.textField.text = self.myString;
}
I hope I’ve helped.
Is it possible to detail more or include some code? The question is a bit obscure.
– Paulo Rodrigues
Thank you for answering but I already found something similar to what I want [http://answall.com/questions/17472/usando-um-objeto-em-diferentes-metodos-no-objective-c] . What I want has to do with the MVC, and when I asked the question I couldn’t explain.
– LesandroxD23