更改初始视图后如何加载状态栏

时间:2016-02-29 12:32:07

标签: ios objective-c iphone view

显示我的ArticlesViewController时出现问题。此代码效果很好,但是当“文章”页面出现时,没有状态栏。 我认为导航控制器出了问题,所以我试图添加

[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;
    }

1 个答案:

答案 0 :(得分:0)

ArticlesViewController中添加以下方法试一试。

- (BOOL)prefersStatusBarHidden
{
    return NO;
}

如果您尚未设置plist,则需要为每个控制器设置。

您也可以在didFinishLaunchingWithOptions:

中添加以下行进行设置
[[UIApplication sharedApplication] setStatusBarHidden:NO];

enter image description here

enter image description here

检查plist文件中的这些键,并将设置状态栏初始隐藏为NO