How do I reference the detailViewController on an iPad that is using a splitViewController

一曲冷凌霜 提交于 2019-12-02 05:40:10
5StringRyan

I was puzzled by the templates implementation of the Master/Detail view. I asked a similar question:

How to update DetailView using MasterDetail Application Template

You can use the detailItem (id - so you can pass in a reference) property that is set up by default for the DetailViewController class.

If you have a pointer to the split view controller itself, you can do:

[(GeoDetailViewController *)[[(UINavigationController *)[[splitViewController viewControllers] objectAtIndex:1] viewControllers] objectAtIndex:0] populateDisplay:currentShape];

To get the pointer to your split view, you will probably have to go via your app delegate:

UISplitViewController *splitViewController = [(MyAppDelegate *)[[UIApplication sharedApplication] delegate] splitViewController];

(assuming that you are using the default split view controller template - YMMV depending on how you have implemented it)

Note that when you create your split view, you must set the detail view controller to be a GeoDetailViewController - if you are not and you cannot for app design reasons, I can edit my answer to work around that.

In the master/detail template, Apple uses the following code in the MasterViewController (i.e. the one on the left):

- (void)viewDidLoad {
    [super viewDidLoad];
    self.detailViewController = (MYDetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
}

With the property on MasterViewController defined as:

@property (strong, nonatomic) MYDetailViewController *detailViewController;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!