访问模态视图控制器父级 [英] Access modal view controller parent

查看:70
本文介绍了访问模态视图控制器父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以模态方式呈现ViewController。
如何访问父视图控制器?

I'm presenting a ViewController modally. How can I access the parent view controller ?

我的架构是TabBarController => VC1 => VC2 => VC3 => MVC1,我想达到来自MVC1的VC3。

My architecture is TabBarController=>VC1=>VC2=>VC3=>MVC1, and I want to reach VC3 from MVC1.

在VC3中,我有这段代码:

In VC3, I have this code :

- (void) editAd{
    AskPasswordViewController *modalViewController = [[AskPasswordViewController alloc] initWithNibName:@"AskPasswordView" bundle:nil];

    NSLog(@"modalparent class=%@", [[modalViewController parentViewController] class]);

    [self presentModalViewController:modalViewController animated:YES];
    [modalViewController release];
}

我在MVC1中试过这个:

I tried this in MVC1:

- (void) sendRequest {
    NSLog(@"classe : %@",[[self parentViewController] class] );
}

但它返回我的TabBarViewController ......

but it returns my TabBarViewController...

推荐答案

我这样做的方法就是简单地创建一个委托。在 AskPasswordViewController 的标题中,输入

The way I'd go about something like this is to simply create a delegate. In AskPasswordViewController's header, put

id delegate;

@property (nonatomic, assign) id delegate;

在实现文件中合成它。然后在分配/初始化模态控制器之后,在呈现它之前,设置 modalViewController.delegate = self; 。然后在模态控制器中,您可以调用 self.delegate 从显示它的视图控制器获取信息。我希望这有助于

Synthesize it in the implementation file. Then after you alloc/init the modal controller, and before you present it, set modalViewController.delegate = self;. Then within the modal controller, you can call self.delegate to get information from the view controller that presented it. I hope this helps

这篇关于访问模态视图控制器父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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