2012-08-17 67 views
0

事情的方法是:我有带有触发像这样的IBAction为一个按钮modalViewController该驳回一个`modalViewController`并呈现另一

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

回答

1

因为它们恰好在彼此之后执行实现它(他们不会等待视图消失/出现),它不会被执行。由于屏幕上一次只能有一个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; 
    } 
} 

希望它有帮助!

+0

什么是''isModalViewControllerNeeded? – 2012-08-17 13:06:39

+0

只是一个BOOL属性的例子。你可以自己做。 – Thermometer 2012-08-17 13:09:41

1

这是因为dismissModalViewControllerAnimated需要一些时间来消除动画,并且您打电话给另一个视图以在解除第一个模态视图之前以模态视图呈现,因此呈现模态视图调用被拒绝。完全解散后,如果您不在视图中,则不应执行动画,只有您可以调用其他视图。为了解决使用时间间隔该问题呼叫2或3秒后的本模态的视图或使用完成块dismissModalViewControllerAnimated

可以通过使用本

[delegate performSelector:@selector(presentOtherModalView) withObject:nil afterDelay:3]; 
+0

我怎样才能使用时间间隔? – 2012-08-17 12:56:18

+0

检查我的更新回答 – Sumanth 2012-08-17 13:00:50

+0

它给了我方法'performSelector:withObject afterDelay''找不到的警告' – 2012-08-17 13:05:17

相关问题