Goal C: Use the code to add a toolbar to a UITableView (within the navigation controller)

I managed to add a toolbar at the bottom of my UITableView using the following code:

toolbar = [[UIToolbar alloc] init]; toolbar.barStyle = UIBarStyleDefault; toolbar.frame = CGRectMake(0, 436, 320, 50); //Set the toolbar to fit the width of the app. [toolbar sizeToFit]; [self.navigationController.view addSubview:toolbar]; 

However, when I try to switch to the first page of the navigation controller, the toolbar at the bottom of the page is still displayed. How can I make sure that the toolbar is only displayed in the UITable View, and not any other views in the navigation controller?

Thanks in advance.

ginseng

+4
source share
1 answer

In your TableViewController application:

 - (void)viewWillAppear:(BOOL)animated { self.navigationController.toolbar.hidden = NO; } - (void)viewWillDisappear:(BOOL)animated { self.navigationController.toolbar.hidden = YES; } 
+6
source

All Articles