views:

16

answers:

1

I have a Navigation Controller with a root table view which has several links. Tapping each link moves to the next view (by pushing it to the navigation controller's stack). But suppose that in that "next view", I have a UIButton that should take me further to another view (by pushing on to the same navigation controller's stack)...

View Controller-->first view-->second view-->third view..........

Now, I can easily access the Navigation Controller when I deal with the first view (and successfully push it to the Navigation Controller's stack) because it has been instantiated in the same file itself. What my real doubt is--How do you access a Navigation Controller in a far off view controller (eg, the third view or fourth view etc)? Please note that I am not using any separate delegate. All the Navigation Bar methods have been implemented in one file and connected to the Navigation Controller via an outlet.

A: 

When you push a ViewController onto a NavigationController the ViewController will automatically have it's navigationController property set. This means you can access the same NAvigationController no matter where you are in the stack.

-Update-

navigationController

In every UIViewController you can access that property. So to in any other UIViewController that has been pushed onto the stack you should be able to just do this:

[self.navigationController pushViewController:othercontroller animated:YES];

Look at the documentation for UIViewController to see what other magic properties you have available.

willcodejavaforfood
Yes, that is precisely what I have been trying to do. How exactly do you access that same Navigation Controller. That means, what exactly do you write in "secondViewController.h and .m" files to access the Navigation Controller?