3

Two questions regarding UINavigationController and UINavigatinBar when writing your own container.

1) I created my initial container with a storyboard and embedded it in a UINavigationController. The only way I found for my childViewControllers to access the UINavigationBar was doing something like this in the childViewController's viewDidLoad:

UIBarButtonItem *showDetailViewControllerBBI = [[UIBarButtonItem alloc] initWithTitle:@"Show Details" style:UIBarButtonItemStyleBordered target:self action:@selector(switchToCarouselLayout:)];
self.parentViewController.navigationItem.leftBarButtonItem = showDetailViewControllerBBI;

Is this the proper way to get the UINavigationBar?

2) I thought I could slap in a UINavigationBar onto my initial ContainerViewController. What I did was delete the UINavigatinController in my storyboard and put a UINavigatinBar at the top of my containerViewController. When I run the project, no navigation bar shows. So what does the UINavigationBar in IB actually do if I can't have it in my initial container view controller, without embedding in the UINavigationController? Or is it just for aesthetics and you can only use it with UINavigationControllers? Thanks.

Crystal
  • 28,460
  • 62
  • 219
  • 393

1 Answers1

0

1) Yes, I think that is an OK way to reference something from a child view controller. Another way, would be to define that bar button item in the container controller itself and then set the target to self.childViewControllers.lastObject (assuming there's only one).

2) This should work. Did you drag in a navigation bar, or just change the simulated metrics of the top bar to navigation bar? The latter is only for visual layout in IB, as far as I can tell -- it doesn't actually add one.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • (1) Thanks. I had trouble when trying to still have the back bar button functionality of the navigation controller. (2) i did drag one in from IB and for some reason it did not show... – Crystal Dec 07 '12 at 02:28
  • @Crystal, it's not entirely clear to me what you're trying to accomplish. A little more detail about your setup would be helpful. – rdelmar Dec 07 '12 at 04:56