This class is a subclass of UITabBarViewController.
In my init parent view controller file I have this:
UIBarButtonItem *button1 = [[UIBarButtonItem alloc]
initWithTitle:@"Button1"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(button1:)];
self.navigationItem.rightBarButtonItem = button1;
[button1 release];
And the method:
-(IBAction)button1:(id)sender {
if (self.nvc == nil) {
ChildViewController *vc = [[ChildViewController alloc] init];
self.nvc = vc;
[vc release];
}
[self presentModalViewController:self.nvc animated:YES];
I want to get an value from the parentviewcontroller in my childviewcontroller class, which also is a UITabBarViewController subclass.
How do I do this, I have tried several hours, and I only get a nil-reference.
The object I want to get(which is a property in the parent) is a NSString.
Thanks in advance
There are a lot of ways to do this. The easiest would be to add a property to
ChildViewControllerthat points to your parent view controller. You could call itdelegate. Then the method will look like:Then from the ChildViewController instance you can access
self.delegate.someProperty.There are also ways to get the parent view controller without your own explicit reference (typically
self.tabBarController,self.navigationControllerdepending on context), but the above method is fool-proof, understandable and easy to debug.