I'm trying to update a detailView in a splitViewController. This is what I try:
//Get the application delegate
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
//Get the 开发者_如何学GomasterViewController
MasterViewController *master = [delegate.splitViewController.viewControllers objectAtIndex:0];
This seems to work fine so far. Then I try to update a label in the detailViewController by doing this:
master.detailViewController.myLabel.text = @"someText";
But this doesn't work.
So how is the right way to access the outlets of in the detailView?
Thanks for help.
Define the DetailViewController; in your example the detailViewController is:
DetailViewController *detailViewController = [delegate.splitViewController.viewcontrollers objectAtIndex: 1];
You shouldn't be reaching inside another view controller and changing things. Instead, simply send a message to the DetailViewController, e.g. [detailViewController setCurrentEntry:selectedEntry]
. Better yet, use notifications or KVO to let the DetailViewController observe the selection in the master list. This way, the two view controllers need not refer to each other at all; this is handy when you want to rearrange your app's layout, or use one view controller in isolation, say, in a modal view. Plan for the future.
精彩评论