i've split up my UI into various nib files.
now, i use two nswindowcontroller
subclasses with nsarraycontroller
and nsobjectcontroller
IBOutlets. The nwwindowcontrollers are the File's Owner in their respective nibs.
the controllers are assigned in IntefaceBuilder (IB).
previously in the one nib, i had a binding from an employees nsarraycontroller
to a single employee nsobjectcontroller
, using a controllerkey of 'selection' and modelkeypath of 'self'
now, i try to 'bind' them via code, as such
- (IBOutlet) showEmployeeWindow:(id)sender;
//load a window from a nib file.
...
// Get the employee arraycontroller.
NSArrayController *employeesController = [employeesWindowController employeeArrayController];
// Get the selected employee from the employeeS controller
id employee = [empController selection];
//now the employee
NSObjectController *emplController = [singleEmployeeWindowController employeeController];
//Set the content object of the employee controller as the nsset called employees.
[emplController setContent: employee];
//Show the window.
[singleEmployeeWindowController showWindow:sender];
...
}
The problem.
the debug does shows that a different memory address for the selected employee. ie, the line
id employee = [empController selection];
// Get the selected employee from the employeeS controller
seems to get a different employee.
but i consistently see the first employee never the selected one.
the selected employee is never set as the content -- or more precisely the selected employee doesnt replaces the default first one.
Note that each nswindowcontroller
has a nsmanagedobject
context set via the nsdocument. its the File's Owner in the nib.