所以我有一个在界面生成器中创建的 UITabView 控制器。UITabBarItem 的 title 和 image 属性是在 IB 中设置的。选项卡栏控制器对象存在于 xib 中,并建立了所有必要的连接。我可以调用简单的命令,例如
[tabBarController setSelectedIndex:1];
一切正常,但是当我设置“项目”属性时,我崩溃了。也许我有内存管理问题?
这是崩溃的代码:
NSMutableArray *modifiedItems = [[tabBarController.tabBar items] mutableCopy];
[modifiedItems removeObjectAtIndex:2];
NSArray *newItems = [[NSArray alloc] initWithArray:modifiedItems];
-->[tabBarController.tabBar setItems:newItems animated:NO];
* 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“不允许直接修改由标签栏控制器管理的标签栏。” *在第一次抛出时调用堆栈:
0 CoreFoundation 0x02b9bb99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x02ceb40e objc_exception_throw + 47
2 CoreFoundation 0x02b54238 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x02b541aa +[NSException raise:format:] + 58
4 UIKit 0x005f7019 -[UITabBar setItems:animated:] + 2037
5 Zag Map 0x00003422 -[ZagMapAppDelegate iPodTouchRemoval] + 270
6 Zag Map 0x00002eea -[ZagMapAppDelegate applicationDidFinishLaunching:] + 551
7 UIKit 0x003faf80 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1252
8 UIKit 0x003fd3b0 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 346
9 UIKit 0x004073ec -[UIApplication handleEvent:withNewEvent:] + 1958
10 UIKit 0x003ffb3c -[UIApplication sendEvent:] + 71
11 UIKit 0x004049bf _UIApplicationHandleEvent + 7672
12 GraphicsServices 0x03357822 PurpleEventCallback + 1550
13 CoreFoundation 0x02b7cff4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
14 CoreFoundation 0x02add807 __CFRunLoopDoSource1 + 215
15 CoreFoundation 0x02adaa93 __CFRunLoopRun + 979
16 CoreFoundation 0x02ada350 CFRunLoopRunSpecific + 208
17 CoreFoundation 0x02ada271 CFRunLoopRunInMode + 97
18 UIKit 0x003fcc6d -[UIApplication _run] + 625
19 UIKit 0x00408af2 UIApplicationMain + 1160
20 Zag Map 0x00002ca0 main + 102
21 Zag Map 0x00002c31 start + 53
terminate called after throwing an instance of 'NSException'
我的 NSArray 和 NSMutableArray 似乎很好,因为它们直接来自功能正常的 UITabBar。它返回三个对象,然后是两个。我希望我只是在这里忽略了一些愚蠢的事情。任何想法我都会非常感激。