嵌套父控制器中的调用方法 [英] Call method in nested parent controllers

查看:41
本文介绍了嵌套父控制器中的调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a UIViewController that has an UIPopoverController that has an UINavigationController then a UIViewController. How can I from the child UIViewController call a method (eg. -(void)update) in the parent UIViewController? tried many combinations but still didn't work.

推荐答案

在您的孩子中:

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

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

In your parent controller, when instantiating your child:

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

newChild.parent = self;

...

现在在您的孩子中,您可以推荐给您的父母.例如,您孩子中的某种方法:

now in your child you have a ref to your parent that you can use. For instance, some method in your child:

- (IBAction)someAction {
    [self.parent doSomethingParentsDo];
}

这篇关于嵌套父控制器中的调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆