How to pushViewController when more than one tableViewControllers (no storyboards)
I don't know how to implement a detail view of a table view controller, when that table view controller comes up as a result of user interaction with a tab bar controller that is not the primary view for the app. I think I need to create a second UINavigationController but I don’t know how to integrate it into the master and detail view controllers that will use it, though I have a navigation controller that works for my primary view controller (EdgewoodSecretsMasterViewController)
I’m not yet using storyboards.
My app’s root view is a table view controller called EdgewoodSecretsMasterViewController The user can select a row in the table it populates, display a detailed view, and return to the EdgewoodSecretsMasterViewController table view.
I also have a tab bar on the bottom of this main view. It has 3 choices. One is EdgewoodSecretsMasterViewController It comes up when the user starts the app. The user can select a row in the table, view info on a detail view about that choice and return to the table view.
In app delegate I create vcMaster , an EdgewoodSecrets class
EdgewoodSecretsMasterViewController *masterViewController = [[EdgewoodSecretsMasterViewController alloc] initWithNibName:@"EdgewoodSecretsMasterViewController" bundle:nil]; UINavigationController * vcMaster = [[UINavigationController alloc] initWithRootViewController:masterViewController];
The second tab bar choice is an informational view the author information page. The user can select it, and return to the original table view but clicking on the first tab bar choice
WhoIsAuthor* vcAu = [[WhoIsAuthor alloc] init];
These two choices work as I want them to. But not the third tab. Third tab is vcImportant
ImportantMasterViewController* vcImportant = [[ImportantMasterViewController alloc] init]; initWithNibName:@"ImportantMasterViewController" bundle:nil ];
Here I put all the tab choices into the tab bar controller
UITabBarController *tabBar = [[UITabBarController alloc] init]; NSArray* controllers = [NSArray arrayWithObjects:vcMaster, vcAu,vcImportant, nil]; tabBar.viewControllers = controllers; [[self window] setRootViewController:tabBar];
The third tab choice brings up another table view - ImportantMasterViewController. That table view populates with several choices, but when the user makes a choice, the pushViewController directive doesn’t know anything about the original navigation bar controller. At the push point self.navigationController doesn't have a value. I think this is because the tab bar controller is the root view controller. So I think it's the highest level/in charge I don't know to say that.
I see that Alok Singh responded “For each tab you need to create a separate navigation controller”
I can create a second UINavigationController object in my appDelegate. But I don't know how to use it beyond setting it up in the app delegate like this
UINavigationController * ncImportant = [[UINavigationController alloc] initWithRootViewController:importantMasterViewController];
Seems like somewhere there must be one stack, that holds the last object that got pushed. It seems like I should be pushing all my view controllers on that stack.
In EdgewoodSecretsMasterViewController I push my detail view like this
[self.navigationController pushViewController:self.detailViewController animated:YES];
The detail view comes up The user can go back and forth
In WhoIsAuthor I don’t bring up a detailed subordinate view
In ImportantMasterViewController I attempt to push my detail view like this
[self.navigationController pushViewController:self.importantDetailViewcontrollers animated:YES];
The detail view does not come up. I know that execution gets to this point. I can also see that self.navigationController doesn't have a value like it did in EdgewoodSecretsMasterViewController at this point
And that is - if I understand the other posting right - because it needs it's own navigation controller. But I don't know how to associate the navigation controller I create (ncImportant) in the app delegate with this push
I don't know how to think this through, or what to go and read to understand it.
Thank you Laurel
You need put all the tab choices into the tab bar controller with ncImportant not vcImportant
UITabBarController *tabBar = [[UITabBarController alloc] init]; NSArray* controllers = [NSArray arrayWithObjects:vcMaster, vcAu,ncImportant, nil]; tabBar.viewControllers = controllers; [[self window] setRootViewController:tabBar];
Make UITabBarController as your rootViewController.
Add all the tabs, in each tab you can initialise it with either
a) UINagivationController which in turn is initialised with a UIViewController instance. b) Or just your UIViewContollers
On load of your app, you can always select a Specific Tab that should be shown up.
Then further, you can use either a Push or a Modal methods to show up the OtherViewContollers1 as the details to your selected item in one of the TabBarController's item.
See this :
- This is my Root ViewController ( A Tab bar with Three Tabs in it)
This is a DetailViewController which has a UITableView as instance in it. It is modally presented on t he TabBar when I click an item in the above table View.
See how it is being presented Modally.
Hope that Helps.