[英]Crashing when adding custom view controllers to UITabBarController
將自定義視圖控制器添加到UITabBarController時,我的iOS 6應用程序最近開始崩潰。
我的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];
然后,一切都完美加載。 我究竟做錯了什么?
問題可能是您正在嘗試將nil對象插入字典中,因為此處沒有字典,這可能是第一個視圖控制器循環內發生的事情。
哇,最后它與在UINavigationBar中使用自定義字體有關。 顯然,它是在設置字體之前嘗試初始化NavController-因此,當我嘗試訪問視圖時,它便崩潰了。 瘋。 謝謝大家的幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.