Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Yefo

macrumors newbie
Original poster
Jun 6, 2011
2
0
Hello, I'm new to programming on the iPhone and I've run into a problem.

I've implemented a navigation bar that pushes and pops views. However here is my issue:

current stack of views: [view 1, view 2, view 3]
target stack of views: [view 1, view 2, view 4]

In other words, I understand the basics of how to push/pop views with the navigation bar, but is there a way to basically switch the top view?

This is what I've tried, but it does not work. I think what these two lines of code do is get rid of the top view, then add a new view ON TOP of the view I just got rid of. In other words, these two lines result in the stack being [view 1, view 2] and do not work as I intended.

Code:
[self.navigationController popViewControllerAnimated:NO];
[self.navigationController pushViewController:newView animated:NO];
 
Okay, I solved the problem! I added a pointer to the view 2's class to the headers of view 3 (and view 4).

So when I'm at [view 1, view 2] before I push view 3, i set view 3's point to view 2 so I have a reference to the "parent" class (like in ActionScript). Then, the code becomes:

Code:
[self.navigationController popViewControllerAnimated:NO];
[mainController.navigationController pushViewController:newView animated:NO];

Where "mainController" is just a reference to view 2 and newView is the newly created view 4, allowing me to go from

[view 1, view 2, view 3]

to

[view 1, view 2, view 4]
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.