顯示我的ArticlesViewController時出現問題。這段代碼很好用,但是當Articles頁面出現時,沒有狀態欄。 我覺得有什麼毛病導航控制器,所以我試圖添加如何在更改初始視圖後加載狀態欄
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
無論是在AppDelegate中的didFinishLaunchingWithOptions和ArticlesViewController的viewDidLoad中和viewWillAppear中,但仍然沒有結果
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Entity"];
localStorage = [[context executeFetchRequest:fetchRequest error:nil] mutableCopy];
NSObject *obj = [localStorage valueForKey:@"isAppLaunchedOnce"];
NSString *condition = [[[obj description] componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] componentsJoinedByString:@""];
NSCharacterSet *unwantedChars = [NSCharacterSet characterSetWithCharactersInString:@"\"()"];
condition = [[condition componentsSeparatedByCharactersInSet:unwantedChars] componentsJoinedByString:@""];
if ([condition isEqual: @"YES"]){
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *rootViewController = (ArticlesViewController*)[storyboard instantiateViewControllerWithIdentifier:@"ArticlesViewController"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.window.rootViewController = rootViewController;
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1){
navController.navigationBar.tintColor = [UIColor whiteColor];
navController.navigationItem.titleView.tintColor = [UIColor whiteColor];
NSDictionary *titleAttributes = @{
NSFontAttributeName:[UIFont fontWithName:@"Helvetica-Bold" size:14.0],
NSForegroundColorAttributeName:[UIColor whiteColor]
};
navController.navigationBar.titleTextAttributes = titleAttributes;
}
[self.window makeKeyAndVisible];
}
// Override point for customization after application launch.
return YES;
}
如果您有主要故事板,爲什麼要在代碼中創建導航控制器和文章視圖控制器? – matt
@matt據我瞭解,我不創建ArticlesViewController,我從故事板獲得這個控制器,然後改變我的initialViewController在應用程序。如果你認爲我可以使用我現有的導航控制器 - 問我如何,它可能是一個答案 – dimazava