Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the right way to add a ToolBar to a UITableView?

Tags:

I'm writing a Navigation-Based iPhone app, and I'd like to have a UIToolBar docked at the bottom of my screen, with a UITableView scrolling between the tool bar and the navigation bar.

I've seen a couple of forums where it's been suggested that the View Controller handling this view should be a standard UIViewController rather than a UITableViewController. The view controller would have to implement the UITableView delegate and data source methods in addition to all of the standard UIViewController overrides. What (if any) built-in functionality do I need to recreate in this view controller subclass other than the aforementioned protocols to have it act like a UITableViewController? Is there anything I'm losing by going this route?

Or would it be better to nest a UITableViewController inside of a standard UIViewController?

like image 824
Frank Schmitt Avatar asked Jul 02 '09 05:07

Frank Schmitt


2 Answers

As of OS 3.0 the Navigation Controller has a tool bar built in. To make it appear:

[self.navigationController setToolbarHidden:NO]; 

By implmenting:

- (void)setToolbarItems:(NSArray *)toolbarItems animated:(BOOL)animated 

in your view controller, you can configure the items of the tool bar.

So you no longer have to worry about where the tool bar is located in your hierarchy.

(corrected typo)

like image 79
Corey Floyd Avatar answered Dec 03 '22 14:12

Corey Floyd


Corey Floyd is mostly correct, except that

[self.navigationController setToolBarHidden:NO]; 

should be

[self.navigationController setToolbarHidden:NO]; 

That is, the "b" in "setToolbarHidden" must be lowercase. Also, method name listed in the iPhone OS Reference is actually

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

though it seems that omitting the animated parameter works too.

like image 41
Vic Avatar answered Dec 03 '22 13:12

Vic