I have a tab bar controller with two tabs:
- tabBar1View with a button named “openDifferentView” and a textfield
“myvalue” with text “test” - tabBar2View with a textfield named
“txtInTab2”
When I tap on openDifferentView i want tabBar2View to show, and pass the value “test” (from tabBar1View.myvalue.text) to txtInTab2 (in tabBar2View).
I get the view to show up using [self.tabBarController setSelectedIndex:1] but I’m unsure how I can set the value of its textfield, from this view.
I thought this would be possible:
UIViewController *tab2;
tab2 = [self.tabBarController.viewControllers objectAtIndex:1];
tab2.txtInTab2.text = "something"; //doesn't work
tab2.show; //don't know how to this
Edit: I have already added IBOutlet @property/@synthesize for the textfield in tabBar2View, and #import “tabBar2View.h” in tabBar1View.
UIViewController doesn’t have a property called txtInTab2. txtInTab2 is a property you’ve added to your own UIViewController subclass (which you’ve called TabBar2View).
The code is basically right, but you need to define tab2 as being whatever type of view controller it actually is. From your comments below, it’s actually a navigation controller, so you’ll need to do this:
Then to actually show it, you need to do this via the tab bar controller, like this: