Saturday, June 8, 2013

UINavigationController setToolbarHidden animated example in Objective C (iOS).


UINavigationController setToolbarHidden animated

Changes the visibility of the navigation controller’s built-in toolbar.

- (void)setToolbarHidden:(BOOL)hidden animated:(BOOL)animated

Parameters
hidden
Specify YES to hide the toolbar or NO to show it.
animated
Specify YES if you want the toolbar to be animated on or off the screen.

Discussion of [UINavigationController setToolbarHidden animated]
You can use this method to animate changes to the visibility of the built-in toolbar.

Calling this method with the animated parameter set to NO is equivalent to setting the value of the toolbarHidden property directly. The toolbar simply appears or disappears depending on the value in the hidden parameter.

UINavigationController setToolbarHidden animated example.
- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setToolbarHidden:NO animated:animated];
    [super viewWillAppear:animated];
}
To hide toolbar:

- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setToolbarHidden:YES animated:animated];
    [super viewWillAppear:animated];
}

Example of [UINavigationController setToolbarHidden animated].
//set up the toolbar
[self.navigationController setToolbarHidden:NO animated:NO];
[self.navigationController.toolbar setBarStyle:UIBarStyleBlackOpaque];  //for example

//set the toolbar buttons
 [self setToolbarItems:[NSArray arrayWithObjects:button1, button2, nil]];  

UINavigationController setToolbarHidden animated example.
- (void)viewDidAppear:(BOOL)animated {
    [[self tableView] reloadData];

    [[self navigationController] setToolbarHidden: NO animated:YES];   
    UIBarButtonItem * logoutButton = [[[UIBarButtonItem alloc] initWithTitle:@"Log out" style:UIBarButtonItemStylePlain target:self action:@selector(logOut:)]autorelease];
    NSMutableArray * arr = [NSMutableArray arrayWithObjects:logoutButton, nil];
    [self setToolbarItems:arr animated:YES];

    [super viewDidAppear:animated];
}

End of UINavigationController setToolbarHidden animated example article.