Using a Popup button in Master-Detail

805 views Asked by At

My Document based, Core Data application (using bindings in IB) has two entities, Employee (with an employeeName attribute) and TimeSheet (with timeDescription and entryDate attributes). Employee has a one(employeeDetails)-to-many(employeeTimeSheet) relationship with TimeSheet.

I'm constructing a Master-Detail set up for a TimeSheet entry.

For the Master I've got a one column tableView which has it's value bound to: EmployeeController (an NSArrayController using the Employee entity), arrangedObjects, employeeName.

I have a detailController (another NSArrayController) which is set up as an NSMutableDictionary which has it's contentSet bound to EmployeeController, selection, employeeTimeSheet.

I then have Detail tableView which has three columns, with their respective value bound to DetailController, arrangedObjects, employeeDetails.employeeName(column 0), entryDate(column 1) and timeDescription(column 2).

Now this all works fine, I can select an Employee from the Master Table and the Detail Table shows all the TimeSheet entries associated with that Employee. I can add entries using the selected Employee, everything works great.

My problem is, instead of having a tableView as a Master view, I wanted an NSPopupButton in it's place from which I can select an Employee and view all the time entries associated with that Employee.

I've tried every combination of content, value, arrangedObjects, selectedObject(s) etc. with every combination of the controllers I have but cannot get the NSPopupButton to behave in a similar way to the single column tableView.

I've searched in vain for more information on this and read through the bindings documentation several times but just keep getting mixed up. I feel this should be relatively simple but I just can't seem to get it. I've been racking my brains for almost two days now before posting on here.

Can anybody point out where I'm going wrong? I'd post code but that isn't really appropriate seeing it's mainly an IB thing.

Billy.

2

There are 2 answers

0
BillySangster On BEST ANSWER

Ok, I found it. I knew that after posting on here I'd find it straight away.

I bound the NSPopupButton content to EmployeeController, arrangedObjects, contentValue to EmployeeController, arrangedObjects, employeeName, and it's selectedIndex to EmployeeController, selectionIndex.

Works great.

Billy.

0
JeanNicolas On

By the way: the detailController will populated with a new employee object "automatically". Make sure to set "managedObjectContext" to the same controller (employeeController).