0

I'm building a Core Data document based application. In the app there's a main view (NSTableView) and an inspector view. Both views are separate nib files. The content of the inspector view should depend on the selected row in the main view. I have three controller files:

  • DocumentWindowController (master controller)
  • ItemsViewController (main view)
  • SchedulesViewController (part of the inspector)

Every controller owns a nib file. How is it possible to change the content of the inspector when the user selects another row in the main view's table?

I tried to make it work as follows:

  • Every controller has it's own NSArrayController, which is set up in the DocumentWindowController. The DocumentWindowController gets its managedObjectContext from [[self document] managedObjectContext]
  • When a user clicks a row in the ItemsViewController's tableView, an NSNotification is posted, with [NSTableView selectedRow] as a parameter. Then a fetch request is being made.

My intuition says I have to do this with Cocoa bindings. I searched on Stackoverflow and google but I just can't make it work. If everything is in one nib file is very easy to accomplish. What is the best/most used way to achieve this?

Thanks in advance!

Rens
  • 269
  • 3
  • 11

1 Answers1

1

You could follow the same paradigm as the table view and create a data source for your inspector view.

@protocol InspectorDataSource <NSObject>
- (void) inspectorView:(InspectorView*)inspectorView managedObjectSelected:(NSManagedObject*)managedObject;
@end

Your inspector view controller would then have the data source as a property.

@interface InspectorViewController : UIViewController{
    @public
    id<InspectorDataSource> dataSource;
}
@property (nonatomic, assign) id<InspectorDataSource> dataSource;
Joel Kravets
  • 2,473
  • 19
  • 16