2016-02-29 95 views
1

顯示我的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; 
    } 
+0

如果您有主要故事板,爲什麼要在代碼中創建導航控制器和文章視圖控制器? – matt

+0

@matt據我瞭解,我不創建ArticlesViewController,我從故事板獲得這個控制器,然後改變我的initialViewController在應用程序。如果你認爲我可以使用我現有的導航控制器 - 問我如何,它可能是一個答案 – dimazava

回答

0

ArticlesViewController中加入下面的方法試試看。

- (BOOL)prefersStatusBarHidden 
{ 
    return NO; 
} 

如果你沒有在plist中設置,那麼你需要爲每個控制器設置。

您也可以僅僅通過增加以下線didFinishLaunchingWithOptions:

[[UIApplication sharedApplication] setStatusBarHidden:NO]; 

enter image description here

enter image description here

檢查這些關鍵的plist文件和設置狀態欄最初還隱藏着如NO

設置
+0

仍然不顯示=( – dimazava

+0

我將此行添加到我的appDelegate並將狀態欄設置爲默認,但它不顯示欄 – dimazava