问题是:我有一个 modalViewController
,它带有一个触发 IBAction 的按钮,如下所示:
-(IBAction)myMethod
{
[self dismissModalViewControllerAnimated:YES];
if([delegate respondsToSelector:@selector(presentOtherModalView)])
{
[delegate presentOtherModalView];
}
}
在作为 modalViewController
委托(delegate)的 Root View 中,我实现了 presentOtherModalView
委托(delegate)方法,它看起来像这样:
-(void)presentOtherModalView
{
AnotherViewController *viewInstance = [[AnotherViewController alloc]initWithNibName:@"AnotherViewController" bundle:nil];
viewInstance.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:viewInstance animated:YES];
[viewInstance release];
}
问题是第二个 modalViewController
没有被呈现。它给我消息 wait_fences: failed to receive reply: 10004003
...这应该怎么做?
最佳答案
因为它们是紧接着彼此执行的(它们不等待 View 消失/出现),所以它不会被执行。因为一次只能有一个 ModalViewController 出现在屏幕上,所以你必须先等待另一个 ModalViewController 消失,然后下一个才会出现在屏幕上。
你可以按照你想要的方式创造性地做到这一点,但我这样做的方式是这样的:
[self dismissModalViewControllerAnimated:YES];
self.isModalViewControllerNeeded = YES;
然后在底层 ViewController 的 viewDidAppear 方法中,我这样做:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if (self.isModalViewControllerNeeded) {
[self presentModalViewController:viewInstance animated:YES];
self.isModalViewControllerNeeded = NO;
}
}
希望对您有所帮助!
关于ios - 一种消除 `modalViewController` 并呈现另一个的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12005984/