我呈现模态视图,它是一个导航 Controller :
UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:photoEditVC];
[self presentViewController:nvc animated:YES completion:NULL];
一旦我完成了模态视图,在 nvc 的可见 Controller 中:
[self.presentingViewController dismissViewControllerAnimated:YES completion:NULL];
结果
知道为什么会发生这种情况吗?
更新: 我意识到这只会发生在关闭 View 之前,我更新共享单例类中的一个值,我用它来跟踪事件。
[[SAStatus current] setValue:@(ua_photoSubmitted) forKeyPath:@"actions.user"];
[self dismissViewControllerAnimated:YES completion:NULL];
但如果我这样做,效果很好:
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[[SAStatus current] setValue:@(ua_photoSubmitted) forKeyPath:@"actions.user"];
}];
或者我可以这样做,而且效果很好:
[self dismissViewControllerAnimated:YES completion:^{
[[SAStatus current] setValue:@(ua_photoSubmitted) forKeyPath:@"actions.user"];
}];
当时,没有其他类观察该变量,所以我不明白为什么它会影响模态视图。
最佳答案
不确定这是导致黑屏的原因,但呈现的 View Controller 应该在自身上调用 dismissViewController,而不是在呈现的 View Controller 上。
[self dismissViewControllerAnimated:YES completion:nil];
关于ios - dismissViewControllerAnimated 导致空屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16615941/