“应用程序尝试在iOs5中以模态方式呈现活动控制器”问题

时间:2012-06-26 08:42:10

标签: iphone ios5 navigation apple-push-notifications modalviewcontroller

在我的iPhone应用程序中,我有两个视图说VC1和VC2。在VC1中,我有一个导航到VC2的按钮。这是VC1中按钮操作中的代码:

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (!appDelegate.vc2) {
    appDelegate.vc2 = [[VC2 alloc]initWithNibName:@"VC2" bundle:nil];
}
[self presentModalViewController:appDelegate.vc2 animated:NO];

(我必须在VC2中保留一些状态,这就是我在appdelegate文件中声明VC2的原因)

在VC2中,为了返回,我使用了[self dismissModalViewControllerAnimated:NO];

当我重复进入VC2并使用按钮操作返回时,没有问题。但我也在我的应用程序中实现了推送通知。因此,当我得到推送时,我在OK按钮上发送nsnotification点击推送通知警报视图,并且在VC1中写入的接收通知方法将接收事件,以导航到VC2。

我在接收通知方法中使用与上面相同的代码导航到VC2。

第二次尝试使用Ok按钮单击警报视图导航到VC2时出现错误Application tried to present modally an active controller,我只在iPhone 4S(iO5)中出现此错误。但如果我使用VC1中的按钮操作重复它,它的工作正常。

修改 详细添加代码:

在appdelegate文件中,推送通知警报视图的操作确定按钮:

[[NSNotificationCenter defaultCenter] postNotificationName:@"VC1" object:nil];

接收通知时在VC1中:

- (void)recieveNotification:(NSNotification *) notification{
        AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        if (!appDelegate.menuVC) {
            appDelegate.menuVC = [[MenuScreenVC alloc]initWithNibName:@"MenuScreenVC" bundle:nil];
        }
        [self presentModalViewController:appDelegate.menuVC animated:NO];
}

和VC1中按钮的按钮操作:

- (IBAction)viewMenuScreen:(id)sender{

            AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
            if (!appDelegate.menuVC) {
                appDelegate.menuVC = [[MenuScreenVC alloc]initWithNibName:@"MenuScreenVC" bundle:nil];
            }
            [self presentModalViewController:appDelegate.menuVC animated:NO];
}

并在VC2中:

- (IBAction)backToVC1:(id)sender{
    [self dismissModalViewControllerAnimated:NO];
}

0 个答案:

没有答案