运行Appdelegate.m时出现应用程序错误(sigabrt错误)



我收到一个SIGABRT错误,我真的很生气,你能帮我吗?我知道这个错误是由应用程序委托中的某些东西引起的。我浏览了几次代码,检查了故事板,但没有问题。甚至Parse也在正确编译。

#import "AppDelegate.h"
#import <Parse/Parse.h>
@implementation AppDelegate 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//  Parse Initialization
.....

//Custom Stuff Initialization
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navigationBar"] forBarMetrics:UIBarMetricsDefault];
// Assign tab bar item with titles
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
UITabBarItem *tabBarItem4 = [tabBar.items objectAtIndex:3];
tabBarItem1.title = @"Dashboard";
tabBarItem1.titlePositionAdjustment = UIOffsetMake(0.0, -5.5);
tabBarItem2.title = @"Interactions";
tabBarItem2.titlePositionAdjustment = UIOffsetMake(0.0, -5.5);
tabBarItem3.title = @"Messages";
tabBarItem3.titlePositionAdjustment = UIOffsetMake(0.0, -5.5);
tabBarItem4.title = @"Me";
tabBarItem4.titlePositionAdjustment = UIOffsetMake(0.0, -5.5);
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"pen_sIMG.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"pen_usIMG.png"]];
[tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:@"comment_sIMG.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"comment_usIMG.png"]];
[tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:@"message_sIMG.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"message_usIMG.png"]];
[tabBarItem4 setFinishedSelectedImage:[UIImage imageNamed:@"star_sIMG.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"star_usIMG.png"]];

// Change the tab bar background
UIImage* tabBarBackground = [UIImage imageNamed:@"tabBarBg-icns.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabBarBg-selc.png"]];
// Change the title color of tab bar items
UIColor *titleNormColor = [UIColor colorWithRed:137/255.0 green:137/255.0 blue:137/255.0 alpha:1.0];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                   titleNormColor, UITextAttributeTextColor,
                                                   nil] forState:UIControlStateNormal];

UIColor *titleHighlightedColor = [UIColor colorWithRed:73/255.0 green:130/255.0 blue:202/255.0 alpha:1.0];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                   titleHighlightedColor, UITextAttributeTextColor,
                                                   nil] forState:UIControlStateHighlighted];

return YES;
}

@end

代码的下一行是错误的

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;

因为self.window.rootViewController;将只返回UIViewController。不是UITabBarController

正确的代码是

 UITabBarController *tabBarController = self.window.rootViewController.tabBarController;

最新更新