问题描述
如何关闭模态然后立即推送另一个视图?
How can I dismiss a modal and then immediately push another view?
我在 didSelectRowAtIndexPath 中添加此代码:
I am adding this code in a didSelectRowAtIndexPath:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
ChatTableViewController *chatVC = (ChatTableViewController*)[storyboard instantiateViewControllerWithIdentifier:@"chatVC"];
[self dismissViewControllerAnimated:YES completion:^{
[[self navigationController] pushViewController:chatVC animated:YES];
}];
模态视图关闭,但之后没有任何反应.有什么想法吗?
The modal view dismisses, but nothing happens after. Any ideas?
推荐答案
你不能将一个视图控制器推到一个被解散的视图中,如果它被解散它就会消失,所以推送另一个视图是不合逻辑的,因为父视图控制器是删除.可能你有这个:- ViewController 1 --> Modal ViewController 2 -->想要关闭 VC2 并推送 VC3
You can't push a view controller into a view dismissed, if it's dismissed it disappears so it's not logical to push another view, cause the parent view controller is deleted. Probably you have this:- ViewController 1 --> Modal ViewController 2 -->Wanted to dismiss VC2 and push VC3
你要做的是- ViewController 1 --> Modal ViewController 2 --> 关闭 VC2 --> 在 VC1 上推送 VC3
What you have to do is- ViewController 1 --> Modal ViewController 2 --> Dismiss VC2 --> Push VC3 on VC1
您可以通过通知来实现.最有效的方法是使用委托,在 VC2 上创建一个委托,当 V1 解除时通知 V1,然后只推送 VC3.
You can do it with notifications. The most efficient way is to use delegates, create a delegate on VC2 that notifies V1 when it dismisses and then just push VC3.
这篇关于关闭模态,然后立即推送视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!