0
votes

I have my first NavigationController set up with root viewcontroller - PhotoViewController, It's a collectionView with grid of images. When image is selected I wan't to present a second navigationController with root controller - DetailViewControler.

My first navigationController is set up in appDelegate. I really don't understand how and where should I create the second. I'm not using IB. At the moment I have this in my DetailViewcontroller viewDidLoad:

    DetailViewController *detailView = [[DetailViewController alloc] init];
self.detailController = [[UINavigationController alloc] initWithRootViewController:detailView];

But when i'm trying to push a new controller, nothing happens. I guess that my code is in wrong place.

When I try to present second controller modally from my PhotoViewController, I have an error(trying to present nil viewController).

2
why do you want to present a second navigation controller? Why not present the detail view after selecting an image so that pressing back will get you back to the PhotoViewController? - kraftydevil
I'm building this app purely for learning purposes. I just wan't to learn how it's done. - Armands L.

2 Answers

2
votes

The common idea is to have a single navigation VC that contains -- and lets you navigate between -- other VCs. In the situation you describe, you wouldn't create another navigation VC. Instead, create just the detail VC and push that onto the existing navigation VC...

// assuming self is a view controller contained by a navigation controller
self.detailController = [[DetailViewController alloc] init];
[self.navigationController pushViewController:self.detailController animated:YES];
0
votes

Use a parent view controller as your initial view controller and add the navigation controllers as children, then transition between them. See this blogpost that I wrote: http://sketchytech.blogspot.co.uk/2012/09/container-view-controllers-parent-view.html