Kev*_*inH 7 asynchronous presentmodalviewcontroller ios
我最近在我的iOS应用程序中遇到了一个UIViewController令人毛骨悚然的情况,我试图连续关闭从我的窗口的rootViewController中呈现的一个,使用:
[rootViewController dismissViewControllerAnimated:YES completion:NULL]
Run Code Online (Sandbox Code Playgroud)
并在此后不久(另一种方法,偶然)提出另一个,:
UIViewController *vc2 = [[[MyViewController2 alloc] initWithNibName:nil bundle:nil] autorelease];
[rootViewController presentViewController:vc2 animated:YES completion:NULL];
Run Code Online (Sandbox Code Playgroud)
问题是,我永远无法让第二个视图控制器显示出来.事实证明,就像我所知道的那样,dismissViewControllerAnimated:completion:需要通过"完成"时间的异步块presentViewController:animated:completion:才能再次正常工作.从我所知道的,这个事实并没有直接记录在Apple的文档中.
我提出的解决方案是使用一个方法来解雇解雇,该方法指定您之后要调用的选择器,如下所示:
- (void)dismissViewController:(UIViewController *)presentingController
postAction:(SEL)postDismissalAction
{
[presentingController dismissViewControllerAnimated:YES
completion:^{
[self performSelectorOnMainThread:postDismissalAction
withObject:nil
waitUntilDone:NO];
}];
}
Run Code Online (Sandbox Code Playgroud)
然后我打电话给:
[self dismissViewController:self.window.rootViewController
postAction:@selector(methodForNextModalPresentation)];
Run Code Online (Sandbox Code Playgroud)
无论如何,我想发帖,因为我环顾四周并且没有看到任何有这个特殊问题的人,所以我认为这对人们理解可能是有用的.而且,我想验证我没有破解具有更好的分辨率设计模式的解决方案.
小智 2
只是为了清楚起见。你是说这段代码不起作用吗?
[myRootViewController dismissViewControllerAnimated:YES completion:^{
[myRootViewController pushViewController:newController animated:YES];
}];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5908 次 |
| 最近记录: |