views:

1047

answers:

3

Hello,

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 masterViewController
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. (ignore the missing at sign in front of the "someText" - I have it, but it seems it's not allowed to put it in this forum.)

So how is the right way to access the outlets of in the detailView?

Thanks for help.

+2  A: 

Define the DetailViewController; in your example the detailViewController is:

DetailViewController *detailViewController = [delegate.splitViewController.viewcontrollers objectAtIndex: 1];

Adam
A: 

Thank you Adam I was looking for this answer for a week now. works great for a multi level navigation with a UISplitViewController

A: 

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.

David M.