I have an iPhone app that I'm building that has the following seutp.
- AppDelegate creates a Navigation Controller and sets it's root controller to a MainController
- MainController creates a TabBarController and adds 5 TableViewControllers to it
When a user clicks a row in the Table I want to push it's view onto the Navigation controller. However, it's navigationController attribute is not set, I would need to access the M开发者_Python百科ainController. I can get around this by creating a property on the TableViewController and passing down the reference to the Navigation controller, but this feels dirty, especially if I would have to keep passing it down with more and more sub controllers. There has to be a better way.
I should note that I'm not using IB on the project.
Thanks!
Why not access it from the app delegate?
This should work anywhere in your code.
-(id)mainController
{
return [[[UIApplication sharedApplication] delegate] rootViewController];
}
精彩评论