我的iOS 6应用程序最近在向UITabBarController添加自定义视图控制器时崩溃了。
我的AppDelegate具有公共属性
@property (readwrite, strong) UITabBarController *TabBarController;
@property (readwrite, strong) ViewControllerTypeA *ViewControllerA; //extends UIViewController Class
@property (readwrite, strong) ViewControllerTypeB *ViewControllerB; //extends UIViewController Class
@property (readwrite, strong) ViewControllerTypeC *ViewControllerC; //extends UIViewController Class
最初,我创建一个标签栏控制器,并将视图控制器添加到此:
- (void)InitializeTabBar {
[self setTabBarController:[[UITabBarController alloc] init]];
UITabBarItem *Tab1 = [[UITabBarItem alloc] init];
UITabBarItem *Tab1 = [[UITabBarItem alloc] init];
UITabBarItem *Tab2 = [[UITabBarItem alloc] init];
[self setViewControllerA:[[ViewControllerTypeA alloc] init]];
[self setViewControllerB:[[ViewControllerTypeB alloc] init]];
[self setViewControllerC:[[ViewControllerTypeC alloc] init]];
[[self ViewControllerA] setTabBarItem:Tab1];
[[self ViewControllerB] setTabBarItem:Tab2];
[[self ViewControllerC] setTabBarItem:Tab3];
[[self TabBarController] setViewControllers:@[[self ViewControllerA],[self ViewControllerB],[self ViewControllerC]] animated:NO];
}
它在最后一行崩溃并出现错误:
由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [__ NSPlaceholderDictionary initWithObjects:forKeys:count:]:尝试从对象插入nil对象[1]'
但是,如果我改为插入默认的UIViewController类,即:
[[self TabBarController] setViewControllers:@[[[UIViewController alloc] init],[[UIViewController alloc] init],[[UIViewController alloc] init]] animated:NO];
然后一切都完美地加载。我做错了什么?
答案 0 :(得分:0)
问题可能是你试图将nil对象插入到字典中,因为这里没有字典,它可能是第一个视图控制器循环内的东西。
答案 1 :(得分:0)