問題描述
我剛剛遇到一個崩潰,顯示 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".
這篇關于“應用程序試圖以模態方式呈現活動控制器"?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!