Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem adding UIBarButtonItems to a ToolBar

I have a UINavigationController with a UITableViewController in it. I want to show a ToolBar on the bottom with UIBarButtonItem's. The ToolBar is showing up, but the buttons won't appear. Anyone knows why?

  - (void)viewDidLoad {
        [super viewDidLoad];
     [[self navigationItem] setTitle:@"Selections List"];
     [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addProjectSearch:)] autorelease]];
        [[self navigationItem] setLeftBarButtonItem:[self editButtonItem]];
     [[super tableView] setDataSource: self];
     [[super tableView] setDelegate: self];

     //Toolbar 
     UIBarButtonItem * logoutButton = [[[UIBarButtonItem alloc] initWithTitle:@"Log out" style:UIBarButtonItemStylePlain target:self action:@selector(logOut:)]autorelease];
     NSMutableArray * arr = [NSMutableArray arrayWithObjects:logoutButton, nil];
     [[self navigationController] setToolbarHidden: NO animated:YES];
     [[self navigationController] setToolbarItems:arr animated:YES]; 
    }
like image 331
Olivier de Jonge Avatar asked Mar 19 '10 06:03

Olivier de Jonge


1 Answers

Replace this line:

[[self navigationController] setToolbarItems:arr animated:YES];

with this:

[self setToolbarItems:arr animated:YES];

In general, you should set toolbarItems on each individual view controller that you push, and not on your UINavigationController itself.

like image 105
Tom Avatar answered Oct 18 '22 08:10

Tom