Saturday, June 8, 2013

UINavigationController toolbarHidden example in Objective C (iOS).


UINavigationController toolbarHidden

A Boolean indicating whether the navigation controller’s built-in toolbar is visible.

@property(nonatomic,getter=isToolbarHidden) BOOL toolbarHidden

Discussion of [UINavigationController toolbarHidden]
If this property is set to YES, the toolbar is not visible. The default value of this property is YES.

UINavigationController toolbarHidden example.
To show toolbar in new view controller just add this:

- (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 toolbarHidden].
-(id)initWithNibName:(NSString*)name bundle:(NSBundle*)bundle;
{
  self = [super initWithNibName:name bundle:bundle];
  if (self) {
    self.title = @"My Title";
    NSArray* toolbarItems = [NSArray arrayWithObjects:
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
                                                      target:self
                                                      action:@selector(addStuff:)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch
                                                      target:self
                                                      action:@selector(searchStuff:)],
        nil];
    [toolbarItems makeObjectsPerformSelector:@selector(release)];
    self.toolbarItems = toolbarItems;
    self.navigationController.toolbarHidden = NO;
  }
  return self;
}

UINavigationController toolbarHidden example.
- (void)viewDidLoad { 
    [super viewDidLoad]; 
 
    self.title = @"My View Controller"; 
    // hide the navigation bar 
    // use setToolbarHidden:animated: if you need animation 
    self.navigationController.toolbarHidden = NO; 
}  

End of UINavigationController toolbarHidden example article.