how to access superviewcontroller from its subviewcontroller in iphone
I have a viewcontroller and i am adding a subviewcontroller in that. Now i want to set value for a string from subviewcontrol开发者_C百科ler which is in its superviewcontroller.
Please Suggest some idea
Thank You
if you want to access superview use the statement said by Jhaliya, If you want to access superviewcontroller property frm subviewcontrller property , use
id mainViewController = [self.view.superview nextResponder];
here mainViewController is the superviewcontroller reference.
There a parentViewController property in UIViewController class reference, This property is used for navigation, tab bar, and modal view controller hierarchies.
The above syntax is used for when you are setting a view as subview to a parentviewcontroller
You can access the super view controller using the parentViewController
property on every UIViewController.
UIViewController *parent = self.parentViewController;
You can use superView method of UIView to access its parrent.
UIView *mySuperView = [MySubView superView];
use superview property of UIView
.
UIMyView* mySuperView = (UIMyView*) myView.superview ;
mySuperView.mytextString = @"Assign string to super view";
EDITED:
You could get the list of all your UIViewController
by using methods of UINaigationController
.
Also current visible controller and top view controller,
Read the documentation for UINavigationController .
精彩评论