Reputation: 391
Say I have a class1 and it has a view with a UITextField and a save button that saves the text of the field in an array. Now I also have a class2. In this class2, I want to load the class1 view with the tap of a button. However, I went to set the value of the UITextField before I show this view, so that when class1 appears the UITextField already has a string in it and is editable with a tap. Is this possible?
Edit: Only class2 knows what the textfield value will be
Edit: I tried this
[newInkView setInkTextField:[appDelegate.inks objectAtIndex:indexPath.row]];
NSLog([appDelegate.inks objectAtIndex:indexPath.row]);
[self.view addSubview:newInkView.view];
[self presentModalViewController:newInkView animated:YES];
but this wasn't able to set the text field value. The NSLog did display some value though
Upvotes: 2
Views: 274
Reputation: 47759
Why not set a property of your view controller with the value and have the VC copy the value to the text field in viewWillAppear??
Upvotes: 0
Reputation: 13773
To get the text sent from the class you can do something like this in class1:
-(void)setTextString:(NSString*)value
{
yourField.text = value;
}
As long as you call it before you show the view it'll be there when the view is loaded, granted you have an instance of class1 in class2.
Edit:
This was fixed by using NSUserDefaults to save the string before the view was loaded and load it when it was loaded.
Upvotes: 1