2

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.

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

Thanks for help.

Piotr Byzia
  • 3,183
  • 7
  • 40
  • 62
user270477
  • 23
  • 1
  • 4

2 Answers2

5

Define the DetailViewController; in your example the detailViewController is:

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

Adam
  • 51
  • 1
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.

David M.
  • 3,647
  • 22
  • 26