我提出了一个模态视图,它是一个导航控制器:
- UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:photoEditVC];
- [self presentViewController:nvc animated:YES completion:NULL];
一旦我完成了模态视图,在nvc的可见控制器中:
- [self.presentingViewController dismissViewControllerAnimated:YES completion:NULL];
结果
任何想法为什么会这样?
更新:
我意识到这只发生在解除视图之前,我更新共享单例类中的值,我用来跟踪事件.
- [[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"];
- }];
当时,没有其他类观察者那个变量,所以我不明白为什么它会影响模态视图.
解决方法
不确定这是否会导致黑屏,但是呈现的视图控制器应该自己调用dismissViewController,而不是在呈现视图控制器上.
- [self dismissViewControllerAnimated:YES completion:nil];