嵌套父控制器中的调用方法

Fas*_*sid 1 iphone cocoa-touch objective-c

我有一个UIViewController有一个UIPopoverController,它有一个UINavigationController,然后是一个UIViewController.我如何从子UIViewController中调用父UIViewController中的方法(例如 - (void)update)?尝试了很多组合,但仍然没有奏效.

MrO*_*MrO 5

在你的孩子:

@interface MyChildController:UIViewController {
    MyParentController *parent;
}
@property(nonatomic, assign) MyParentController *parent;
@end
@implementation MyChildController 
@synthesize parent;
...
Run Code Online (Sandbox Code Playgroud)

在您的父控制器中,实例化您的孩子时:

MyChildController *newChild = [[[MyChildController alloc] initWithNibName:nil bundle:nil] autorelease];

newChild.parent = self;

...
Run Code Online (Sandbox Code Playgroud)

现在,在您的孩子中,您可以使用您父母的参考资料.例如,您孩子的一些方法:

- (IBAction)someAction {
    [self.parent doSomethingParentsDo];
}
Run Code Online (Sandbox Code Playgroud)