“应用程序试图以模态方式呈现活动控制器"?

时间:2023-03-24
本文介绍了“应用程序试图以模态方式呈现活动控制器"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我刚刚遇到一个崩溃,显示 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 数组.

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 Developer Preview 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]];

现在你正在尝试做这样的事情:

Now you are trying to do something like this:

[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".

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

上一篇:使用正则表达式查找/替换 NSString 中的子字符串 下一篇:为应用程序设置默认的 iOS 本地通知样式

相关文章