views:

95

answers:

2

I am developing for iPad and have created a standard UISplitViewController application using the template provided in Xcode - a standard UITableView on the left and a detail view on the right.

I have modified the template so that when a user selects a table cell from the left view it pushes a new table view in it's place (still on the left side). This works without issue, but I would like to be able to update the existing detail view from the new table view - kinda like how Apple's Mail application works.

- I am not trying to create multiple views on the detail view (right hand side) - I've read the documentation and seen the sample code provided by Apple.

I read/followed many tutorials, but can't seem to get this relatively simple view hierarchy to work.

More detail:-

Using detailViewController.detailItem = @"Test"; in the RootView didSelectTableRowAtIndexPath delegate method updates the Detail view label. Using the exact same code in the newly pushed Table View does not update the label - am I missing a reference point or something??

Since posting I've tried to use protocols & delegates to update a label on the detail view. The label updates correctly when changed from the Root View using the new methods, however, when I push a new view onto the root view (left hand side) I can no longer update the label.

+1  A: 

Try the viewControllers property of your UISplitViewController

@property(nonatomic, copy) NSArray

*viewControllers Discussion The array in this property must contain exactly two view controllers. The view controllers are presented left-to-right in the split view interface when it is in a landscape orientation. Thus, the view controller at index 0 is displayed on the left side and the view controller at index 1 is displayed on the right side of the interface.

The first view controller in this array is typically hidden when the device is in a portrait orientation. Assign a delegate object to the receiver if you want to coordinate the display of this view controller using a popover.

Sander Backus
As far as I can tell the viewControllers property of UISplitViewController is used to assign view controllers to the view (!). I think my issue here is to do with delegation or protocols. No matter what I try I cannot seem to get it to work... any other suggestions?
KSoza
+1  A: 

At some point after creating the RootViewController (or maybe even in a custom init method) you are setting the delegate for the DetailViewController, its a common mistake that when a new rootViewController is pushed onto the NavController that you forget to set the delgate again.

You probably are creating a new controller in the:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;

method and recording/incrementing the level of the new controller before you push it onto the navController. After you create this new controller, set the delegate again.

newRootController.myDelegate = self.myDelegate;

Before you do this If you NSLog the delegate just before you use it, you will probably find its nil.

Luke Mcneice
Thank you very much, worked a charm! I had already set the delegate when pushing the new view, but I was creating a new instance rather than referencing the existing delegate. Thanks again!
KSoza