Reputation: 15628
Hi to all,
I passed a variable from first.m to seViewController.m. I'm able to print that variable using NSLog(@variable) but I'm unable to use textField.text=variable. How to print that variable in a textbox?
First.m
-(void)buttonPressed01
{
seViewController *seView = [[seViewController alloc] init];
[seView insert:myString];
[self.navigationController popViewControllerAnimated:YES];
}
seviewcontroller.m
-(void)insert:(NSString*) myString
{
NSLog(@"%@",myString);
textField.text=[NSString stringWithFormat:@"%@",myString];
}
Upvotes: 0
Views: 260
Reputation: 6954
You can use this one if what I understood is correct, you can retrieve the array of viewControllers from the navigation controller. You dont need to initialize the view controller and this wont work as explained above.
Upvotes: 0
Reputation: 11145
I think its not working because you are passing this variable to a new instance of your seViewController while you are popping it in the next line. You have to get the same instance as -
seViewController *seView = (seViewController*)[self parentViewController];
[seView insert:myString];
[self.navigationController popViewControllerAnimated:YES];
Upvotes: 0
Reputation: 11314
seViewController *seView = [[[seViewController alloc] initWithNibName:@"seViewController" bundle:nil] autorelease];
[seView insert:String];
[[self navigationController] pushViewController:seView animated:YES];
seviewcontroller.m
-(void)insert:(NSString*) myString
{
NSLog(@"%@",myString);
textField.text=myString;
}
Upvotes: 2
Reputation: 6402
When you pop from stack it loads the instance of the view controller you pushed in to stack. Here you created a new instance and set the text field and loads the instance in the stack. Thats why text field does not show the value to set. If you want to pass the value to the class you nee to pass the value using some singleton class or app delegate.
Upvotes: 0
Reputation: 8564
Until your seViewController is loaded you can not use its outlets, here you are using textField. It won't set text because after seViewController *seView = [[seViewController alloc] init];
the view is initialized but still you need to load its view in memory in order to use its outlet. so if you are using its view then after addingSubview, or presenting modalView or, pushing it on navigation stack call that method.
or else you should have a string in seviewcontroller which you will set and when controller's will be loaded in memory viewDidLoad
just do what you are doing right now in insert method, set TextField's text.
Also, I am not sure what you want to do with seView? why you are creating new instance and not using it ? May be you have created this controller earlier and you want to change that controller's textField text not the new one. Then in that case you should refer that controller not this one because its totally different object.
Thanks
Upvotes: 0