I have a Container View that holds 1 of 3 view controllers swapped out by 3 tabs (across the bottom).
Here's my Storyboard:
I'm taking this approach so that I can have custom tabs and a single Save button for all the fields in this big form.
How can I access the IBOutlets in those 3 child view controllers from inside my Entry Detail View Controller class?
Here's what I've done to try and access it in the parent.
//EntryFlightInfoViewController.h (Child 1)
@property (strong, nonatomic) IBOutlet UITextField *aircraftIdTextField;
Then in my parent class (Entry Detail View Controller) I can't access the property:
//EntryDetailViewController.m (Parent)
#import "PPEntryFlightInfoViewController.h"
- (IBAction)buttonSave:(id)sender {
NSLog(@"save: %@", _aircraftIdTextField); //(!) Error: Use of undeclared identifier '_aircraftIdTextField'
}
How do I access another view controller's IBOutlets when they are in a Container View? Hopefully I'm on the right track. Forgive me as I'm still quite new to Objective-C. :)
The short answer is you can't unless you write your own communication layer. You can get at the different views via the childViewControllers (mentioned above) as well as getting your own custom pointers in your prepareForSegue method call as the view is loaded into the container view. (see this link for more info on this) This will work great if you are forcing the user to visit each page. If not then the same defaults you'd load there on the first viewDidLoad can likely be saved without checking the specific view controller.
Apple's answer is to never have a save button. If you edit it, you meant it, and it's saved immediately. =)
That said, were I you, I'd have an object that all of the views access to load/unload their data for storage whenever you show/hide the different views, possibly in viewDidLoad/viewDidDisappear. This way you always have a "known good" object ready for saving, and you won't have to directly access those view controllers.
Hope that helps some.