I’m trying to create a basic navigation app using UINavigationController as root container for other inner UIViewController views. I have already achieved similar functionality with shared toolbar. I’m wondering, is it a good approach because the toolbar and its items are redrawed (i think ?) on every inner view. So, here are some details of my existing code. In my main MultiviewAppDelegate.m implementation file, in didFinishLaunchingWithOptions method, I am initializing UINavigationController, then initializing the first inner view (UIViewController) and then adding its view to UINavigationController.
UINavigationController *nc = [[UINavigationController alloc] init];
[self.window addSubview:nc.view];
...
FirstView *v1 = [[FirstView alloc] init];
[nc pushViewController:v1 animated:NO];
[nc setToolbarHidden:NO];
...
All other inner views (like FirstView) extends BaseViewController class (BaseViewController extends UIViewController) because, in my BaseViewController, I have implemented shared toolbar that I want to be visible across inner views. So in the method viewDidLoad of BaseViewController class I’m doing the creation of that toolbar:
- (void)viewDidLoad {
UIBarButtonItem *firstViewBtnItem = [[UIBarButtonItem alloc]initWithTitle:@"FirstView" style:UIBarButtonItemStyleBordered target:self action:@selector(showFirstView)];
UIBarButtonItem *secondViewBtnItem = [[UIBarButtonItem alloc]initWithTitle:@"SecondView" style:UIBarButtonItemStyleBordered target:self action:@selector(showSecondView)];
...
NSArray *items = [NSArray arrayWithObjects:firstViewBtnItem, secondViewBtnItem, ..., nil];
[firstViewBtnItem release];
[secondViewBtnItem release];
[self setToolbarItems:items];
...
The thing is I’m not sure is it good to redraw a toolbar every time every new inner view comes up. So I’m not sure would it be a good decision to do the same with a background. Or maybe, I want too much 🙂
Have you tried just creating a view and adding it to your window before adding the navigation controller’s view? Anyway, unless your background is cpu intensive I can’t imagine it would be a problem including it in every ‘inner view’ – this also gives you more flexibility for the future if you need views without this background or with a slightly different background.