简体   繁体   中英

issue in hiding navigation bar

i add navigation bar in rootController like below in appdelegate

@property (strong, nonatomic) UINavigationController *navController;
@synthesize navController;


birthDateTableViewController =[[BirthDateTableViewController alloc]initWithNibName:@"BirthDateTableViewController" bundle:nil];



navController = [[[UINavigationController alloc]initWithRootViewController:birthDateTableViewController]autorelease];


[window addSubview:navController.view];
[window makeKeyAndVisible];
 return YES;

now as i want to hide it in other view because they have their own navigation bars so i use following code for hiding rootViewControllers navigation bar but its not hiding please tell me what i am doing wrong i do this for hiding in viewDidLoad

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.navController setNavigationBarHidden: YES animated:NO];

application get crash when it reach above line i have tried this which is not working [self.navigationController setNavigationBarHidden: YES animated:NO];

Your appDelegate doesn't have a link to the navController but your viewController has one! So change your code for:

[self.navigationController setNavigationBarHidden: YES animated:NO];

我认为这样会很好。

[self.navigationController setNavigationBarHidden: YES animated:YES];

Try this in your view controller's -(void)viewWillAppear method in which you don't want to show navigation bar.

- (void)viewWillAppear:(BOOL)animated
{
     self.navigationController.navigationBarHidden = YES;

    [super viewWillAppear:animated];
}

Rather using...

  [window addSubview:navController.view];

Use this...

  [window addSubview:self.navController];

And in your viewControllers, use this...

  self.navigationController.navigationBarHidden = YES;

For iOS < 6.0 use

[self.window addSubview:navigationController.view];

For iOS >= 6.0 use

[self.window setRootViewController:navigationController];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM