父视图控制器和模型视图控制器解除检测不起作用
我有一个名为 ShowListViewController 的 UIViewController,它使用模态视图控制器将另一个视图推送到堆栈上:
AddShowViewController *addShowViewController = [[AddShowViewController alloc] init];
[addShowViewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentModalViewController:addShowViewController animated:YES];
然后,当 <代码>addShowViewController消失。
我认为此处找到的答案会起作用,但事实并非如此。我的方法 populateTableData
未被检测为可选方法。
本质上我的问题是:如何检测模态视图控制器何时消失,以便调用类中将其推入堆栈的方法?
I have a UIViewController called ShowListViewController
that uses a Modal View Controller to push another view onto the stack:
AddShowViewController *addShowViewController = [[AddShowViewController alloc] init];
[addShowViewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentModalViewController:addShowViewController animated:YES];
I would then like to call my method populateTableData of the ShowListViewController
class when the addShowViewController
disappears.
I would think that the answer found here would work, but it doesn't. My method populateTableData
is not detected as an optional method to use.
Essentially my questions is: How do I detect when a Modal View Controller disappears so as to call a method within the class that pushed it on the stack?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这可能不是最好的解决方案,但此时可以做你想做的事。
在您的 showlistcontroller 中添加一个实例变量
,然后在进行模态演示之前将其值设置为 YES,就像
在 ShowListViewController 的 viewWillAppear 中一样,您可以检测它是否出现,因为 pop 被解雇或不像
This may not be a best solution, but can do what you want at this time.
In your showlistcontroller add an instance variable like
and before you do the modal presentation set its values as YES like
in the viewWillAppear of ShowListViewController you can detect whether it is appearing because pop getting dismissed or not like
我想你会喜欢这样的东西。
你在你的 modalVC 中创建一个委托,如下所示:
并在你的 MainVC 中实现它,如下所示:
然后你将在你的 modalVC 中创建一个委托属性,如下所示:
将 ModalVC 的 dismissDelegate 设置为 MainVC,然后创建委托方法。然而,在您关闭它之前,您将调用 ModalVC 做最后一件事。 (这是填充你的表)。您将在 MainVC 中调用数据,然后在关闭 modalVC 之前执行您想做的任何操作。
希望它有帮助;)
I think you would like something like this.
You make a delegate inside ur modalVC like this:
and implement it in your MainVC like this:
Then u will make a delegate property in your modalVC like this:
You set the dismissDelegate of your ModalVC to your MainVC and then you make the delegate method. Before you dismiss it however you will call the ModalVC to do one last thing. (which is populate your table). You will call for the data inside your MainVC and then do whatever you feel like it, just before you dismissed your modalVC.
Hope it helps ;)
好吧,看来在 Apple 的
Utility App's
模板中,他们忽略了 [UIViewController][1] 的文档所说的内容,实际上不遗余力地调用dismissModalViewControllerAnimated:
将模态视图推送到屏幕上的UIViewController
。您的情况的基本思想是
AddShowViewControllerDelegate
定义一个协议,ShowListViewController
实现此协议,。示例只需使用
Utility
模板创建一个新项目,然后查看FlipsideViewController
和MainViewController
的源代码下面是一个适合您需求的示例:
AddShowViewController.h
AddShowViewController.m
ShowListViewController.h
ShowListViewController.m
OK so it appears that in Apple's template for
Utility App's
they ignore what the docs for [UIViewController][1] say and actually go out of their way to calldismissModalViewControllerAnimated:
from theUIViewController
that pushed the modal view onto screen.The basic idea in your case will be
AddShowViewControllerDelegate
ShowListViewController
implement this protocolFor a full example just create a new project with
Utility
template and look at the source forFlipsideViewController
andMainViewController
Here is an example adapted for your needs:
AddShowViewController.h
AddShowViewController.m
ShowListViewController.h
ShowListViewController.m