解雇一次后如何呈现相同的modalView

时间:2011-11-15 08:58:45

标签: cocoa-touch modalviewcontroller

我在第一次出现模态视图控制器时遇到了一些问题,所以我只是启动了一个小测试方法,它会出现,解散并再次呈现相同的控制器模式。

// This is just test Code.
MYViewController *vc = [[MYViewController alloc] init];
[self presentModalViewController:vc animated:YES];
[self dismissModalViewControllerAnimated:YES];
[self  presentModalViewController:vc animated:YES];

我收到错误:

2011-11-15 09:50:42.678 Proyecto3[1260:11603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <RootViewController: 0x6d9d090>.'

文档不会在这里添加任何线索。

3 个答案:

答案 0 :(得分:1)

@David,使MYViewController成为一个实例变量,并将其初始化为:

if (myInstance==nil)
     //create instance of MYViewController
     //myInstance.delegate=self
//present modal VC

MYViewController中,创建一个协调解雇MYViewController的协议可能位于donecancel按钮上。在按钮操作中调用一些像

的东西
    done 
    {
       if([delegate respondsToSelector:@selector(willDismissModalView)])
       {
           [delegate willDismissModalView];
       }
   }

并在你的VC willDismissModalView方法中解雇MYViewController。这样你就可以做到这一点。

答案 1 :(得分:0)

在你的代码中[self dismissModalViewControllerAnimated:YES];  将不会对modalViewController执行任何操作,因为这里的“self”是viewController,您尝试在其中呈现modalViewController“vc”。再次提示已经呈现的modalViewController。这将导致终止。

您可以在该viewController中解除modalViewController vc,此处为vc。

答案 2 :(得分:0)

在动画制作时,您无法呈现/关闭视图控制器,我认为这可行

MYViewController *vc = [[MYViewController alloc] init];
[self presentModalViewController:vc animated:NO];
[self dismissModalViewControllerAnimated:NO];
[self  presentModalViewController:vc animated:YES];

但我真的没有理由这样做,为什么你要解雇并重新呈现已经呈现的模态视图控制器?

相关问题