Reputation: 23503
I am building an app with a tableView
and a couple details pages. I started with the masterViewController
template, but found that I wanted to customize my tableView
layout, so I deleted the navigationController
and added a viewController
with a tableView
inside. Everything is working great, except for the fact that I can't get out of the detailView
. I added a navigation bar to the top of the detailView
with a cancel
button, but the [self.navigationController popToRootViewControllerAnimated:YES];
isn't working (I'm guessing because there is no nav controller). I've also tried using the popToViewController
method, but couldn't get that to work either.
My question is then: What do I have to do to be able to "pop" views? I'm assuming that the views are being pushed somewhere when I go from the tableView
to the detailView
via the segue, so how do I go back? Do I have to use some form of navigationController
?
Any direction or help would be great!
Upvotes: 0
Views: 87
Reputation: 11597
short answer: yes
dont delete the navigation controller, otherwise you wont be able to pop and push views (you can still use modal transitions though)
all a navigation controller really is, is a manager for a array of viewControllers. if you look at the self.navigationController.viewControllers
property, you can access the navigation chain, and change it how you want by putting it into a NSMutableArray
and doing changes and assigning it back. just FYI.
Upvotes: 1
Reputation: 29094
Using NavigationController will be a good choice according to me..
If you are using NavigationController, you could use [self.navigationController popViewControllerAnimated:YES];
instead of popToRootViewController to pop and to push
[self.navigationController pushViewControllerAnimated:YES];
If you use "views", then use [self.view removeFromSuperview]
to remove the whole view, or remove all views use this:
for (UIView *view in [self.view subviews])
{
[view removeFromSuperview];
}
Hope this helps..
Upvotes: 1
Reputation: 2085
in order to navigate through your app, your app requires a navigation controller, if you are setting up the app in storyboard you can drag the navigation controller from the right side and then link it to a view controller.
your popping code probably isn't working because you have no navigation controller aka self.navigationController is nil,
if you are making the app mostly in code you may can allocate a navigation contorller
UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController: masterViewController];
from there you can push to other pages or pop to previous pages
adding a navigation bar to the top of your page in the storyboard doesn't give your view controller navigating functionality, it is simply user interface objects just sitting there, if you want to set the ui navigation bar to your actual navigation bar then you may set it in code
[self.navigationController setNavigationBar:navigationBarProperty];
so to answer your question, you need a navigation controller and in the story board -> navigation controller -> tableView -> detailView should do the trick
Upvotes: -1