从presentModalViewController / dismissModalViewControllerAnimated返回后调用的是什么? [英] what's called after returning from presentModalViewController / dismissModalViewControllerAnimated:

查看:126
本文介绍了从presentModalViewController / dismissModalViewControllerAnimated返回后调用的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显示我的mainView模式uiview我使用:

to show a modal uiview out of my mainView I use:

[self presentModalViewController:myController animated:YES];

并且在MyController中我关闭该视图:

and in MyController I close that view with:

[self dismissModalViewControllerAnimated:YES];

但是我怎么知道在mainView模态已经完成
目前我在mainView中设置一个局部变量为YES,在启动模式视图后对viewWillAppear作出反应:

But how can I know in the mainView that the modal was finished (to redraw my table)? Currently I set a local variable to YES in my mainView after starting the modal view an react on viewWillAppear:

[self presentModalViewController:myController animated:YES];
_reloadTableData = YES;

-(void)viewWillAppear:(BOOL)animated {
   [super viewWillAppear:animated];
   if (_reloadTableData) {
     _reloadTableData = NO;
     [_tableView reloadData];
   }
}

有更好的方法吗? p>

Is there a better way to do so ?

推荐答案

一般来说,不适合通过模态视图本身关闭模态视图。

Generally speaking, it's not appropriate to dismiss the modal view by the modal view itself.

而应将主视图设置为模态视图的代理。当模态视图完成其任务时,它可以让它的委托知道并让它的委托人将其关闭。这是Objective-C中非常常见的所谓委托设计模式。

Instead, you should set your main view as the delegate of the modal view. When you modal view finishes its task, it can let its delegate know and let its delegate dismiss it. This is the very common so-called delegate design pattern in Objective-C.

btw,您可能需要参考一些代码示例,以便更好地了解此代理模式。我建议您查看Xcode的默认模板之一 - 实用程序应用程序模板。它有一个非常简洁,简单和直接的代理结构内部构建。

btw, you may want to consult with some code samples to gain a better understanding of this delegate pattern. I suggest you take a look at one of Xcode's default templates - the Utility Application template. It has a very succinct and simple and straightforward delegate structure built inside.

这篇关于从presentModalViewController / dismissModalViewControllerAnimated返回后调用的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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