pop 2 views from navigation controller stack problem
Hello, I'm using a navigation bar on which I push several views according to what the user selects. At certain point I need to pop 2 views from the stack. (I need to go from view 3 to view 1 - it's not the root view, it`s just to explain my problem)
I`ve tried using the method "popToViewController:" in many ways, but I can't make it work
Then I decided to try another approach, making 2 pops simultaneously from the navigation stack. One from view 3 and the other at view 2 in the "viewWillAppear" method (under a specific condition, so that it doesn't pop every time it loads the view).
The app pops to the view I want (view 1), but the navigation items (title, back button, add button) are the ones of the 2nd view, not the 1st.
I've moved the declaration of the segmented control and add button al the view 1 from the viewDidLoadMethod to the viewWillApear, I debug it and it runs the code, but it still displays the wrong information at the navigation bar.
Im not sure what you've tried, and what you haven't tried.. I am taking a stab here and guessing, based on your descriptions, but what I might try would be to put a method in view controller 1
Thanks for the quick reply. I've tried it, but I get the same problem, it pops to the view I want, but the navigation bar still displays the info of the second view.
I really donīt understand why this happens. Do I have to unload the navigation bar items somewhere, or that is not necessary?
Thanks for the quick reply. I've tried it, but I get the same problem, it pops to the view I want, but the navigation bar still displays the info of the second view.
I really donīt understand why this happens. Do I have to unload the navigation bar items somewhere, or that is not necessary?
I've never had to do that... that's really strange... let me chew on it for a few.
I've ran into this some times. Its the animation. Until the first pop finishes you can't pop again or the nav bar buttons will bug on you. Change the second pop to viewDidAppear and see if it helps. This way it will pop back and pop again one animation at a time.
If you need to pop straight to the right controller you can try
Code:
int count = [self.navigationController.viewControllers count];
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:count-2]];
I've ran into this some times. Its the animation. Until the first pop finishes you can't pop again or the nav bar buttons will bug on you. Change the second pop to viewDidAppear and see if it helps. This way it will pop back and pop again one animation at a time.
If you need to pop straight to the right controller you can try
Code:
int count = [self.navigationController.viewControllers count];
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:count-2]];
Thanks a lot nobre!!! I changed the second pop to viewWillAppear and it worked perfectly!!
I have a new problem related to this, though I think it has nothing to do with the pops.
On the first view I have a mutable array with Person information, and for each cell I load a nib and display the information of each element of the array.
On the 3rd view, when I delete an element of the array, I make the 2 pops, but sometimes the app crashes when it tries to load the 1st view and it gives me this message:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UISegmentedControl nick]: unrecognized selector sent to instance 0xd5cce0'
nick is a property of the Object Person that is displayed in the cell, but I never use it on the segmented control
I load the segmented controll this way at viewWillAppear:
I've ran into this some times. Its the animation. Until the first pop finishes you can't pop again or the nav bar buttons will bug on you. Change the second pop to viewDidAppear and see if it helps. This way it will pop back and pop again one animation at a time.
If you need to pop straight to the right controller you can try
Code:
int count = [self.navigationController.viewControllers count];
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:count-2]];
will return a number that is one more than the index for the current view. If you're popping multiple controllers, you will want to subtract one plus the number of controllers your moving back.
Another way, which might be more inelegant (but it works) is to assign a pointer to the navigation controller, then call popViewController:animated twice:
From the second view I have to start this whole application which is in this link.
ie., in first page i need only a button and from the next page this application which is in the link must start.can any one help me
From the second view I have to start this whole application which is in this link.
ie., in first page i need only a button and from the next page this application which is in the link must start.can any one help me