When hitting the Back button on a navigation controller, does the view get popped off the stack? If so, how can I test that or make sure that it does it correctly (in other words, created a proper navigation controller)?
I need to see if the view is actually getting popped. Is there anything I can NSLog that shows me the stack or something?
Thanks,
Yes, the view is popped from the stack. You can check the size of the stack (number of views) to confirm this.
The viewController is getting popped from the stack yes. You can also NSLog(#"%#", self.navigationController.viewControllers); in - (void)viewWillAppear and - (void)viewDidAppear methods of the parent viewController to see the differences if you don't trust that Apple engineers did a good job with it.
NSLog(#"%#", self.navigationController.viewControllers); would give the viewcontrollers array in navigation stack.you can nslog them before the view disappears and after the other view appears
Related
I'm writing an iPhone app that is based on a UINavigationController. I'm pulling data from a server that sometime returns bogus links. I open each link by pushing a webview viewcontroller. I want to be able to include some error handling. I know if the link is no good. So I want to be able to pop the webview view controller as soon as I know that my webview has encountered an error.
Currently, I've tried using the following code:
[self.navigationController popViewControllerAnimated:YES];
I then get a Navigation bar with nothing displayed in it, but if I click where the "back" button should be it operates appropriately. The title pops up when I click where the "back" button should be. The view where the viewcontrollers usually display there content is blank white too even though I'm popping back to a UITableViewController.
I've tried this as a workaround:
UINavigationController *nav = self.navigationController;
[self.navigationController popViewControllerAnimated:YES];
[nav.visibleViewController.view setNeedsDisplay];
I've checked the viewControllers array in the UINavigationController and it has the right viewcontrollers in it (ie it has removed the viewcontroller for the webview).
I also tried putting code in the viewWillAppear of the viewcontroller I'm popping back to, but the method is never getting called.
I'm looking for a way to force the UINavigationController to reload the same way that you can call reloadData on a UITableView.
Any help would be greatly appreciated.
I saw something like this on my app where I was using a navigation bar I added in Interface Builder on the root view of a navigation controller and then programmatically creating the nav bar and its subviews for the second view. When I would pop the second view to return to the first view I would hide the self.navigationcontroller bar which would show the white space underneath until the IB nav bar of the previous view appeared. To fix this I decided to stick with programmatically creating all my navbars which fixed the issue for me.
TL;DR - if you are using both IB and programmatically made navbars this can happen when popping views, stick with one or the other for all the navbars yo
I have a tabbar controller app with two tabs. One of my tabs uses a navigation controller.
The navigation controller that I made for this resides in View A. View A acts solely as a controller and automatically pushes View B which in turn pushes view C which pushes View D.
I want the next view to be View B, so I used
NSArray *viewControllers = [[self navigationController] viewControllers];
int i=0;
while (! [[[viewControllers objectAtIndex:i] nibName]
isEqualToString:#"ViewBController"]
&& i < [viewControllers count])
i++;
to get the view I want (in some cases the order of the views may change so I don't want to hardcode it)
and then
self.navigationController popToViewController:[viewControllers objectAtIndex:i] animated:NO];
to get back to view B
My issue is that the app crashes at this point. Well technically it crashes after it deallocs View C (I put nslogs there to figure that out).
I have no idea what my issue can be? Can anyone provide insight?
EDIT: I also tried making a new view controller, View E, and pushing that and it still crashes
I finally figured out my problem, it turned out not to be a navigation issue.
Before switching views I had an alert that I set to autorelease, and then I also released it.
I figured this out by using NSZombie, which is awesome.
For anyone who needs the reference check this out:
http://cocoadev.com/index.pl?NSZombieEnabled
First, a clarification... When you say that your nav controller resides "in View A" what exactly do you mean? Do you mean it is the View Controller contained on the first tab?
So far it looks like you might have a fundamental misunderstanding of how to use a navigation controller. They aren't supposed to be loaded so that you can flipped through to whichever one you want. Each view controller in the navigation controller should be a new screen that your user has chosen to navigate to. It sounds like you are trying to populate the nav controller with a bunch of view controllers and then push or pop to one of them in the middle, but that's not really how it works.
Here is a video explaining how to use a UINavigationController, perhaps it will help. http://vimeo.com/2371881
i have an application based on an navigation controller. At first, it presents a Modal View with the Log In interface. After the user logs in, i dismiss this view and present the rootViewController.
Then, in the nav bar i have a button in order to show the Profile view in wich i can log out.
The problem is the following. When i press log out in the Profile View i do two things:
Present a new Modal View with the log in screen.
Pop the profile view controller.
But for a moment, i can see the pop action and the RootViewController before the Log In View is shown.
How can avoid this behavior?
Thanks
You need to specify that you do not want to see the animation. Where are you popping the last view controller from?
It should probably be something like this
[navController popViewControllerAnimated:NO];
Hey,
I think you must have the animated flag either on - (void)dismissModalViewControllerAnimated:(BOOL)animated or
on - (UIViewController *)popViewControllerAnimated:(BOOL)animated set to YES so you are actually able to see it switching views. If you change them to NO the "Log in" view will come up right away.
I hope this is useful for you.
Regards
I am using Tab bar + navigation based application and I have 4 tab bars. When I navigate from one view controller to another view controller, the viewWillAppear: method doesn't seem to respond and I am being forced to call it manually by creating the object of the next view controller. So my question is, how do I avoid calling the viewWillAppear: method manually whenever I navigate from one view controller to another? Instead, it should get triggered automatically just like the viewdidLoad: method gets triggered when you navigate from one view controller to other. Please guide me on how could I do that.
Hoping for the best possible Answer
Thanks in Advance
You are correct, viewWillAppear is a little special, it is usually called automatically but in some cases including when you are adding a view controllers view manually (view addSubview:), and also when adding this as a view controller to a UITabBarController or UINavigationCnotroller (of which you have both !) it doesn't get messaged.
This however is only for the root view, as you navigate (maybe with a navigation controller) back and forth, that root view's viewWillAppear will get triggered as some point.
In short, if you need to implement something in viewWillAppear in these cases, you should message it yourself when you know it's going to be presented. You can handle this case in your view controller, check out the following article about the matter:
http://www.touchthatfruit.com/viewwillappear-and-viewdidappear-not-being-ca
Good luck.
You should check UITabBarDelegate then look for the method:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item.
Description: Sent to the delegate when the user selects a tab bar
item.
In some apps that have a tab bar controller, each tab also needs a nav controller before a view can be added:
[[[_mainTabController topViewController] navigationController] pushViewController:renewalScreen animated:YES];
Do you mean 4 tab items on a tab bar, rather than '4 tab bars'? If you have a tab bar with tab items, the viewWillAppear: methods absolutely should be called by the system as the tabs are selected by the user. You could have other issues that are causing the problem.
You didn't forget to call [super viewWillAppear] somewhere?
Try using the viewDidAppear method instead.
Trying to fix a very strange error, i have 3 view controllers that start from the app delegate and push each other accordingly. The 3rd view controller then has a toolbar button that calls the code here:
-(void)showEventBrowser;
{
accelManeger.delegate = nil;
NSLog(#"%u",[self.navigationController.viewControllers count]);
[self.navigationController popToRootViewControllerAnimated:NO];
}
This works the first time round but when i come back to this view controller and try again. Firstly it reports that there are 3 view controllers on the stack. It then deallocs the 2nd view controller in the stack and doesnt crash but will not go any further. If i hit the button again it says there are no view controllers on the stack and fails to respond.
I have logs for all the viewdid, viewwill, e.t.c in each view controller and there appears to be no odd behaviour. Also no memory warnings from any view controllers.
Why would this work once through but not the second time ?
Well i Fixed this.
I was trying to poptorootviewcontroller from a viewcontroller that had no view but isntead just displayed a UIImagepickercontroller. Even when attempting to dissmiss this modalviewcontroller first, (even with a delay), i still had the same problem. I instead changed the viewcontroller in question to a UIMagepickercontroller subclass and handle the present and dismiss in another viewcontroller.
Lesson learnt, dont pop to root with UIImagepickercontroller modal view ontop.