I have an UITableViewController which I would like to add UIToolbar to with one button. In the
- (void)viewDidLoad;
method of UITableViewController I have:
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(pressButton1:)];
self.navigationItem.title = @"Some title";
self.navigationItem.leftBarButtonItem = button;
}
Unfortunately I don’t see the toolbar when I run my app.
Any hints? Should I do something more?
The
navigationItemproperty of a view controller is useless if that controller is not displayed inside aUINavigationController.If your view controller is inside a navigation controller I don’t know what the problem is.
Otherwise you can use an
UINavigationItembut you need to create aUINavigationBaryourself.Either in the Interface Builder (add a
UINavigationBarand add aUINavigationItem, then connect theUINavigationItemto a property outlet declared your view controller (you don’t need to connect the Bar).Or in your code :