问题是:我在modalViewController上显示了一个按钮,该按钮会触发IBAction,如下所示:

-(IBAction)myMethod
{
    [self dismissModalViewControllerAnimated:YES];

    if([delegate respondsToSelector:@selector(presentOtherModalView)])
    {
        [delegate presentOtherModalView];
    }
}


在作为该modalViewController委托的根视图中,我已经实现了presentOtherModalView委托方法,它看起来像这样:

    -(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 ...该怎么办?

最佳答案

因为它们是彼此完全执行的(它们不等待视图消失/出现),所以它不会被执行。由于一次只能在一个屏幕上显示一个ModalViewController,因此您必须先等待另一个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;
    }
}


希望能帮助到你!

09-11 19:27