简体   繁体   English

视图控制器调用模式视图

[英]View controller calling a modal view

How can I reliably determine the name of the view controller that called a modal view from within that modal view? 如何可靠地确定从模态视图中调用模态视图的视图控制器的名称? The app has a singleton so I was planning to add a view controller there and save the name of the calling view controller. 该应用程序有一个单例,因此我打算在此添加一个视图控制器,并保存调用视图控制器的名称。 .parentController gives me the name of the nav controller. .parentController给我导航控制器的名称。

EDIT I tried a sample project and it did just as mine did so I think maybe were not on the same page. 编辑我尝试了一个示例项目,它的工作方式与我的一样,所以我认为可能不在同一页面上。 I appreciate your working with me on this one. 感谢您与我一起完成这一工作。 I downloaded a project from 我从下载了一个项目

http://sites.google.com/site/iphonesdktutorials/sourcecode/UINavigationControllerWithToolbar.zip?attredirects=0

added 2 lines and changed 1 and it demonstrates what I am getting. 添加了2行并更改了1行,它演示了我所得到的。 It took me all of 5 minutes, if that. 我花了整整5分钟,如果那样的话。 In RootViewController.m, info_clicked (line 147), above the last line add, 在RootViewController.m中,在最后一行上方的info_clicked(第147行)中添加,

NSLog(@"calling: %@", [[self navigationController] visibleViewController]); 

then, per your instructions, in the last line change self.navigationController to self. 然后,按照您的指示,在最后一行将self.navigationController更改为self。 This controller is what I want to get from the modal. 我想从模态中得到这个控制器。 Then in InfoViewController.m, viewDidLoad (line 35), before the closing curly brace add, 然后在InfoViewController.m中,添加viewDidLoad(第35行),然后添加右花括号,

NSLog(@"Parent: %@", [self parentViewController]); 

Change the Base SDK Project Settings to 4.0, Build, open your console and press the Info Button on the bottom. 将基本SDK项目设置更改为4.0,生成,打开控制台,然后按底部的信息按钮。 I'm getting UINavigationController for parentViewController and I want RootViewController. 我为parentViewController获取UINavigationController,并且我想要RootViewController。

You're probably using [self.navigationController presentModal...] instead of [self presentModal...] . 您可能正在使用[self.navigationController presentModal...]而不是[self presentModal...] If you use self , parentViewController will work. 如果使用selfparentViewController将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM