2011-05-01 52 views
4

刚过我的代码调用presentModalViewController dismissModalViewControllerAnimated有问题

- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match 
{ 
    [menuViewController dismissModalViewControllerAnimated:YES]; 
    [GameKitWrapper getSingleton].match = match; 
    match.delegate = [GameKitWrapper getSingleton].remotePlayer; 
    [menuViewController presentModalViewController:avatarSelectionViewController 
             animated:YES]; 
} 

但我有问题,该辞退工作,但不是现在。当我更改dismissModalViewControllerAnimated:YES dismissModalViewControllerAnimated:没有它工作,但不好看。

任何帮助表示赞赏。

回答

5

@adam有正确的想法,但你不想再等待一段任意延迟。这是脆弱的,因为它可能需要花费任何时间来完成动画。你想等待先前的视图控制器实际完成解散。根据我的经验,最好的地方在于您当前的视图控制器的viewDidAppear:。这将在你的模态完全消失后被调用。有关解决类似问题的一些示例代码,请参见this question

+0

这个答案是正确的。 – adam 2011-05-02 08:04:15

+1

我在这里有一个替代(http://stackoverflow.com/a/8317603/126855),不需要覆盖viewDidAppear :. – Bill 2011-11-29 20:56:45

0

尝试等待第二....

- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match 
{ 
    [menuViewController dismissModalViewControllerAnimated:YES]; 
    [GameKitWrapper getSingleton].match = match; 
    match.delegate = [GameKitWrapper getSingleton].remotePlayer; 
    [self performSelector:@selector(presentModal) withObject:nil afterDelay:1.0]; 
} 

- (void)presentModal { 
    [menuViewController presentModalViewController:avatarSelectionViewController 
              animated:YES]; 
} 
+1

亚..驳回,并在同一runloop呈现一个UIView控制器可能会导致真正的UI问题,甚至崩溃(至少在以前的我使用的SDK)。而且我经常发现它不能保证简单地延迟呈现下一个视图控制器。正因为如此,我完全避免了这种设计。 – 2011-05-01 14:25:37

+0

等待一段时间是脆弱的。如果时间太长,应用程序将不必要地无响应;如果太短,你现在的通话将失败。我发现一个解决方案不依赖于计时:http://stackoverflow.com/a/8317603/126855 – Bill 2011-11-29 20:56:08

-1

尝试调用:

[menuViewController dismissModalViewControllerAnimated:NO]; 

调用之前:

[menuViewController presentModalViewController:avatarSelectionViewController 
        animated:YES]; 
+0

-1提问者已经尝试过,并且反对缺乏解除视图控制器的动画,并且不希望它消失。 – zachjs 2012-10-11 00:05:51

相关问题