I've created an application with serial views (A,B,C,D,...), and I need to pop back D to B. Someone may say Why not using:
[self.navigationController popToViewController:[[self.navigationController viewControllers] objectAtIndex:1] animated:YES];
However, it is not a good solution. Because this method needs you to get the index which our "B" is store in.
Question: How to get the index of "B" in the viewControllers?
format in the UIViewControllers
should be:
"< A: 0x6e70710 >",
"< C: 0x6e30370 >",
"< B: 0x6988a70 >",
"< D: 0x6ea8950 >",
"< E: 0x6eaaad0 >"
I've tried and failed to use rangeOfString
and hasPrefix
to get the "B" view's index.
You could probably do something like:
Update:
In iOS 6, you can just use unwind segues, which takes care of all of this for you. Just go to your B class, define an unwind action (identified as such by the combination of the
IBAction
return type and theUIStoryboardSegue
parameter), e.g.:Then, any controller that's presented by B can then can create an unwind segue by, for example, control-dragging from a button to the exit icon in the scene's dock. You can optionally have the controller that you're unwinding from do the expected
prepareForSegue
(which is called before B's unwind action).Here i would like to know you that NavigationController manage the ViewController by the
Concept Of Stack
.ieLAST COME FIRST OUT
.Here are two Approach for doing the Same.1)Here you can make iteration for getting the desirable ViewController as Below
2) Here you have
A,B,C,D
Controllers. meansB
would be on 3rd Position so what can you doyou can hard wired the Index as Below
I hope it may helpFull to you..