Keep Toolbar at top of UIView when using pushViewController and then popViewController?

StackOverflow https://stackoverflow.com/questions/3781867

  •  04-10-2019
  •  | 
  •  

سؤال

Update: Another solution to this problem would be if the Navigation bar at the root level of the navigation controller could be transparent or not shown. Is there a way to make the Navigation bar at the root level of the navigation controller transparent or not shown?

I have a NIB with a toolbar at the top of my top level UIView and below the toolbar is a tableView. When I use pushViewController on a navigationController to push another UIViewController onto the navigationController, the toolbar is overwritten by the navigation bar. When I pop the current view back to the root view, the toolbar cannot be seen as there is a blank bar across the top. There is now also a gap between the toolbar and the top of the tableView about the size of the toolbar. So the view looks like from the top: 1) shaded blank bar, 2) blank space about the size of a toolbar, 3) tableview

How can I make the toolbar of the top level NIB appear at the top of the UIView after using popViewController?

In the top level view I instantiate a UINavigationController:

 self.navigationController = [[UINavigationController alloc] initWithRootViewController:ListsController];

and then in didSelectRowAtIndexPath I push a view controller

ItemsController * Items  = [[ItemsController alloc] 
                                         initWithNibName:@"Items" bundle:nil] ;
[self.navigationController pushViewController:Items animated:YES];

To get the initial pushed view to display I do the following:

UIView *navView = self.navigationController.view;
CGRect navFrame = navView.frame;
//  navFrame.origin.y -= 20;
navView.frame = navFrame;

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
UIWindow *appWindow = appDelegate.window;


[appWindow addSubview:navView];

Any idea how I can get the top level toolbar not to be overwritten when popping back to the top level?

هل كانت مفيدة؟

المحلول

The solution is to make the navigation bar hidden at the root level using:

- (void)viewWillAppear:(BOOL)animated {
[[self navigationController] setNavigationBarHidden:YES animated:YES];

[super viewWillAppear:animated];
[self.table reloadData];
}

Then at the next lower level of the navigation stack, make the navigation bar unhidden:

- (void)viewWillAppear:(BOOL)animated {
[[self navigationController] setNavigationBarHidden:NO animated:YES];

[super viewWillAppear:animated];
[self.table reloadData];
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top