0

i implemented a navigation controller which has 10+ view.. here by swiping right in view am switching to the next view... swiping left will bring u the previous page. here i used poptoviewcontroller for go to prevous page.

in each of every page it has a menu to switch over to desired view. after jumping to the particular view if we swiping left will brings previously visited view instead of this i just want to go the previous page as per the menu...

here i used all the property of poptoviewcontroller but it doest work any suggestion.

thnks,

nik
  • 2,289
  • 6
  • 37
  • 60

3 Answers3

0

You have to think of the Navigation's view controllers as a stack (like a stack of papers on you desk).

So, if push something on to the stack, when you pop something off the stack, it'll be the previous item.

I'm not sure what you're doing, but I would look at the documentation for UINavigationController's setViewController:Animated method. I think it'll help with your problem.

mackross
  • 2,234
  • 17
  • 19
  • is it possible to add all viewControllers in a common stack before pushing and popping.. – nik Jan 05 '11 at 08:58
  • you could have an nsarray that contains all the view controllers and then make a copy that is setup for what you want to display, you could then use setViewController:(NSArray)array animated: However, I feel what your doing would be better off done with a UIScrollView? – mackross Jan 06 '11 at 14:40
0

Let me explain you what is nvaigationcontroller stack.

Stack = {root, A, B, C, D}.

The current visible view is D. When you make pushViewController(E) is means that you added a new view to the stack, which becomes visible: Stack = {root, A, B, C, D, E}. When you make popViewController you deleted the last element of the stack and set the new last element to be visible, in our case it becomes : Stack = {root, A, B, C, D} again and D is visible. Now if you choose popToRootController(A) it means you remove all the elements from the stack untill the top element is A and it becomes visible so in our case it's Stack = {root, A}.

I hope I understood correctly your question and explained you so that you could understand correctly the hierarchy. If not, please reformulate your question.

Oleg Danu
  • 4,149
  • 4
  • 29
  • 47
  • Hi danu thanks for u reply here what am doing is from the controller A (as per u r example) i pushing the viewController D. if i do popToController in D it will go to 'A' instead of this i jus wan to go to prevoius onr ie 'C' view controller.. – nik Jan 05 '11 at 08:57
  • 1
    You can't do that. Because you don't have C in the stack, as I understand. As I understand initially you have the next situation. Stack = {root, A} you make pushVieController(D), our stack now is Stack = {root, A, D}. We don't have any C view in the stack. I understand that you have this logic and you want to go back to C. I recommend you - (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated from the same class. – Oleg Danu Jan 05 '11 at 10:00
  • In this case you will be able to do next thing: Stack = {root, A}; You add [navigationController setViewControllers:(NSArray *){B,C,D} animated:NO) your stack will become Stack = {root, A, B, C, D} and this case when you will press Back or use popviewController you will go from D to C. – Oleg Danu Jan 05 '11 at 10:05
  • thanks Danu its working now but poptoviewcontroller animation is not working... here my code 4 ur ref.. NSArray *popStack = [NSArray arrayWithObjects:reviewsTableViewController, genotypeViewController,nil]; [self.navigationController setViewControllers:popStack animated:YES]; [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES]; – nik Jan 05 '11 at 11:58
  • Without any animation view is appearing... here want the animation like backbutton property.. – nik Jan 06 '11 at 08:52
  • hmmm maybe you try to make animaitons yourself. Check UIView's beginAnimations – Oleg Danu Jan 06 '11 at 14:31
0

finally i solved this issue. but not using setViewController method infact.

here while pushig the view itself i added the views in stack. ie for example i want go to the view A to D means i added b and c with pushviewcontroller animated:NO; and D with animated:YES;

So it worked perfectly for me....

nik
  • 2,289
  • 6
  • 37
  • 60