I was trying to do this, add a UIToolbar to a Navigation Controller (UINavigationController),
I found this example Navigation Controller + UIToolbar but it inserts the toolbar programmatically.
I have been playing with the Interface Builder until I have managed to include the toolbar with minimal code, this way...
First, you have to create a new Navigation-Based Application. Then you open MainWindow.xib with the Interface Builder and include a Toolbar bellow the Window.

You must drag the Toolbar from the Library to the Nib document window, bellow the Window object to look this way (selecting this list View Mode):

and then set the position of the toolbar inside the window at the bottom (you can hit twice on Toolbar or Window to make this window appears):

You need to do some coding to make the toolbar appears in the right position:
Inside the application delegate class you need to include an outlet as reference to the Toolbar, in <Applicaton>AppDelegate.h:
@interface Windows2AppDelegate : NSObject {
IBOutlet UIWindow *window;
IBOutlet UINavigationController *navigationController;
IBOutlet UIToolbar *toolbar;
}
@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) UINavigationController *navigationController;
@property (nonatomic, retain) UIToolbar *toolbar;
@end
and in your <Application>AppDelegate.m:
@implementation Windows2AppDelegate
@synthesize toolbar;
[...]
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Configure and show the window
[window addSubview:[navigationController view]];
[window addSubview:toolbar];
[window makeKeyAndVisible];
(and the release if you like in the dealloc method).
In the code above the toolbar should be added to the window (
addSubview:) after the navigationController, this way the toolbar is visible.And finally link the Toolbar in the Interface Builder with toolbar outlet in our code.


and that’s it.
If you are interested, The original article provides additional source code about how to move among views.
Hi!, I am Eduado Oliveros, if you want to contact me, send an email to eduardo.oliveros(at)gmail dot com
1 comentario:
Thank you for the great article.
I added a couple of enhancements to my implementation.
1. Set the bottom inset value in the tableview to 44 so that the last item in the list is not hidden by the toolbar.
2. The toolbar added to the main window will obscure any toolbars in subviews. I moved the addSubView call to the viewWillAppear method in the tableview viewController and added a removeFromSubview call to the willSelectRowAtIndexPath method in the same viewController. This allows access to the bottom area of the screen for subsequent views.
Thanks again for the great tip
Stephen
Publicar un comentario en la entrada