NSPopUpButton and Bindings
NSPopUpButton and Bindings
- Subject: NSPopUpButton and Bindings
- From: Marcus Roberts <email@hidden>
- Date: Wed, 8 Jun 2005 08:42:24 +0100
Hello,
A quick summary of my problem - I have an NSTableView that holds a
list of 'categories'. When you click a row, it brings up a list of
'Tasks' that have a "belongsTo" Core Data relationship with the
category in a second NSTableView. That works fine.
When I create a new task, I open a new window which has a text field
for entering a task name, and an NSPopUpButton which allows the user
to choose the category for the task. When the user enters some data
and presses OK, I instantiate a new Core Data 'task' object, and it
appears in the list of tasks for the chosen category.
In the second window's nib file, I have an NSArrayController which is
bound to the document's managed context, and is specified as holding
the Category entity type.
The NSPopUpButton is bound to the array controller. Content is bound
to arrangedObjects and contentValues is bound to arrangedObjects.name.
When I run the program, the second window appears with the list
populated with categories, which is exactly what I wanted.
The problem is I want the NSPopUpButton to be pre-selected to the
category already chosen in the first window, but to stay on that
category even if the category selection is changed in the first
window.
To try this, in the window controller for the second window, I have a variable:
NSManagedObject * selectedCategoryObject;
I bind the NSPopUpButton's selectedObject binding to this variable. I
use the following constructor:
- (id)initWithSelection:(NSArray *)selections;
to pass in the value I get from calling this:
[self categoryController]selectedObjects] (where categoryController
is the array controller the NSTableView column in the first window is
bound to.
This actually all works. My problem is that when the window opens,
you can see the NSPopUpButton being redrawn as the bound values are
being put into it. It ends up with the right selection, but it looks
ugly as it does it.
I have two questions that I hope will point me in the right direction.
First of all, is my approach for this the right one? It feels wrong
somehow, as if it's not as elegant as it could be.
The second is about when controls get connected to their bound data.
In awakeFromNib the NSArrayController is empty of bound data. Is
there a delegate function or other notification that gets called when
a controller has been bound? My preferred approach to the problem
above would be not to bind the selectedObject binding, but wait to be
told the array controller has been bound ot its data, and then set the
selection manually.
Any pointers would be much appreciated.
Thanks
Marcus
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden