Ily*_*ski 6 iphone cocoa-touch
我有一个完全适用于iPhone OS 2.2.1的应用程序,但是当我尝试在iPhone OS 3.0上运行它时,它会崩溃.
这是我从控制台得到的错误:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Changing the delegate of a tab bar managed by a tab bar controller is not allowed.'
Run Code Online (Sandbox Code Playgroud)
可能是因为我正在以编程方式更改某个视图控制器的视图.
这是代码:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear: animated];
self.view = current_controller.view;
[current_controller viewWillAppear: NO];
[current_controller viewDidAppear: NO];
}
Run Code Online (Sandbox Code Playgroud)
可能在这部分代码中发生错误,如果是,我该如何解决?为什么会发生呢?
谢谢你,伊利亚.
Mir*_*lav 10
在大多数情况下,您可以使用UITabBarControllerDelegate.它具有与UITabBarDelegate类似的方法,并避免此类异常.例如,代替:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
int index = [tabBar determinePositionInTabBar:item]; // custom method
[tabBar doSomethingWithTabBar];
[item doSomethingWithItem];
[item doSomethingWithItemAndIndex:index];
}
Run Code Online (Sandbox Code Playgroud)
你可以写:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
UITabBarItem *item = [tabBarController.tabBar selectedItem];
int index = [tabBarController.tabBar determinePositionInTabBar:item]; // custom method
[tabBarController.tabBar doSomethingWithTabBar];
[item doSomethingWithItem];
[item doSomethingWithItemAndIndex:index];
}
Run Code Online (Sandbox Code Playgroud)
小智 4
上面的 Ernst 先生给人的印象是,他在 Ilya 的代码中看到了一些构成“从控制器中拉出视图”的东西。这可能会让您长时间盯着代码,但这并不是问题的真正所在。我在苹果开发者论坛http://discussions.apple.com/message.jspa?messageID=10259835#10259835上发布了这个问题,我被告知“NSInternalInconsistencyException”是 .xib 文件的问题(在 Interface Builder 中) 。使用这些信息我找到了以下解决方案。我认为我在这里给出的一些名称是通用的,将为其他尝试解决此问题的人提供帮助。为了检查该问题,xib 参考在 2.x 上编译并完美运行,在 3.x 上编译并在您尝试在 3.0 模拟器中运行应用程序时给出上面的错误消息。我在标签栏中有一个代表。在界面生成器中查看引用出口时,我将“多个”、“文件所有者”、“选项卡栏”和“选项卡栏控制器”作为引用出口。当我从引用插座中删除“选项卡栏”时,我的应用程序在模拟器 3.0 中运行。它还在 2.x 上编译并运行,因此 2.x 不需要“选项卡栏”引用。... 闪电侠戈登