Here is the init method of the root view controller of my navigation controller that I am trying to display the toolbar on:
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:nil bundle:nil];
if(self){
//GUI implementation
self.navigationController.toolbarHidden = NO;
UIBarButtonItem *flexiableItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:self
action:nil];
UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self
action:nil];
self.toolbarItems = [NSArray arrayWithObjects:flexiableItem, item1, nil];
UIBarButtonItem* addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(addEmployee)];
self.navigationItem.rightBarButtonItem = addButton;
self.navigationItem.leftBarButtonItem = self.editButtonItem;
}
return self;
}
and here is my delegate application:DidFinishLaunching
method in the app delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
BOHomeViewController* hvc = [[BOHomeViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController* navbar = [[UINavigationController alloc] initWithRootViewController:hvc];
[self.window setRootViewController:navbar];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
The toolbar is not showing up at all. Could someone point out where I am doing something wrong? Much appreciated.
Move the initializing of your toolbarItems to the initializer you're actually calling ( initWithTableViewStyle:
) and self.navigationController.toolbarHidden = NO;
to viewWillAppear as self.navigationController
will be nil in your intializer.