I have a UIViewController with a UITableView in it, and also added a UINavigationBar.
How can I add and “edit” button and a “+” button in that bar programmatically?
(I have tried using IB, but the title is always replaced, and not other items are added)
I am not using a UINavigationController. is my UIViewController standing alone.
This is what I have tried without success:
UIBarButtonItem *barButton =
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStyleBordered
target:nil
action:nil];
UINavigationItem *editItem = [[UINavigationItem alloc] initWithTitle:@"Title"];
[editItem setLeftBarButtonItem:barButton animated:YES];
[navigationBar setItems:[NSArray arrayWithObject:editItem] animated:YES];
Your
UIViewControllerhas anavigationItemproperty. You can set the left and right bar button items withself.navigationItem.leftBarButtonItem = ...andself.navigationItem.rightBarButtonItem = ...Edit:
OK, I assume you have a reference to your
UINavigationBar?Then I guess you’d add a single
UINavigationItemto it:and then set that item’s left and right buttons:
I haven’t tried this, but I think it should work.