“应用程序尝试以模态方式呈现活动控制器”? [英] "Application tried to present modally an active controller"?

查看:188
本文介绍了“应用程序尝试以模态方式呈现活动控制器”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚遇到一个崩溃,显示了一个 NSInvalidArgumentException ,并在之前没有这样做的应用中显示此消息。

I just came across a crash showing a NSInvalidArgumentException with this message on an app which wasn't doing this before.


应用程序试图以模态方式呈现一个活动控制器
UITabBarController:0x83d7f00。

Application tried to present modally an active controller UITabBarController: 0x83d7f00.

我有一个 UITabBarController 我在 AppDelegate 中创建它,并为它提供 UIViewControllers <的数组/ code>。

I have a UITabBarController which I create in the AppDelegate and give it the array of UIViewControllers.

其中一个我想在点击它时以模态方式呈现。我通过实现委托方法做到了这一点

One of them I want to present modally when tapped on it. I did that by implementing the delegate method

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController

如果该视图控制器属于我想以模态方式呈现的类,我返回NO并且执行

If that view controller is of the class of the one I want to present modally, I return NO and do

[tabBarController presentModalViewController:viewController animated:YES];

现在我收到了这个错误,这似乎意味着你无法以模态方式呈现查看在其他地方活动的控制器(在标签栏中...)
我应该说我在XCode 4.2开发者预览版7上,所以这是iOS 5(我知道NDA,但我想我是没有提供任何禁止的细节)。我目前没有XCode安装来测试这是否会崩溃编译iOS4 SDK,但我几乎完全确定它没有。

And now I'm getting that error, which seems to mean that you can't present modally a view controller that is active somewhere else (in the tabbar...) I should say I'm on XCode 4.2 Developer Preview 7, so this is iOS 5 (I know about the NDA, but I think I'm not giving any forbidden details). I currently don't have an XCode installation to test if this crashes compiling against the iOS4 SDK, but I'm almost entirely sure it doesn't.

我只想要询问是否有人遇到过此问题或有任何建议

I only wanted to ask if anyone has experienced this issue or has any suggestion

推荐答案

假设您有三个视图控制器实例化如下:

Assume you have three view controllers instantiated like so:

UIViewController* vc1 = [[UIViewController alloc] init];
UIViewController* vc2 = [[UIViewController alloc] init];
UIViewController* vc3 = [[UIViewController alloc] init];

您已将它们添加到标签栏中,如下所示:

You have added them to a tab bar like this:

UITabBarController* tabBarController = [[UITabBarController alloc] init];
[tabBarController setViewControllers:[NSArray arrayWithObjects:vc1, vc2, vc3, nil]];

现在你正试图这样做:

[tabBarController presentModalViewController:vc3];

这会给你一个错误,因为标签栏控制器对你的视图控制器有一个死角给它。您可以不将其添加到选项卡栏上的视图控制器数组,也不能以模态方式显示它。

This will give you an error because that Tab Bar Controller has a death grip on the view controller that you gave it. You can either not add it to the array of view controllers on the tab bar, or you can not present it modally.

Apple希望您将其UI元素视为某种方式。这可能隐藏在人机界面指南中,因为不要这样做,因为我们不希望你想要这样做。

Apple expects you to treat their UI elements in a certain way. This is probably buried in the Human Interface Guidelines somewhere as a "don't do this because we aren't expecting you to ever want to do this".

这篇关于“应用程序尝试以模态方式呈现活动控制器”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆