Search code examples
objective-cxcodepointersreferenceuisplitviewcontroller

Getting controller references in splitviewController


I have an application and I need to be able to get reference to the detail controller from the master controller, I dont know how to use the app delegate file yet. Before I used

   [self.splitViewController.viewControllers lastObject]

Which would have my detail controller as the last object, then I embeded a navigation controller and now the lastObject is a navigationcontroller instead of my controller that I needed reference too. How would I get reference to my controller now? is there anyway to have the splitviewcontroller go down the line of controllers its looking at? it loads up the proper controllers but when I call the above method it says navigation controller. thanks


Solution

  • You can access the view controllers in a navigation controller in the same way as a split view controller. The first object in the navigation controllers view controllers will be your root view controller.

    [[[self.splitViewController.viewControllers lastObject] viewControllers] objectAtIndex:0]