 |
 |
Bindings and selected index
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Apr 2004
Status:
Offline
|
|
I have an interface I'm working on where I'd like my model object to supply the data to a table view, but I'd also like to have it keep the selection index up to date.
SO.. I set up bindings, and I bound the table data to an NSArrayController which is bound to the appropriate array in the model object. and it set's the table data, and that's good. And I also bound the selectionIndexes property of the NSArray controller to my model object, and so I can keep track of which item is selected in my model. which is also good.
The problem is that I'd like the table to start by initially selecting the object that I start with selected in my model. I set up a couple logs, and I watch when the window opens as the NSArrayController queries the model for it's selected index, gets the right one, and then proceeds to immediately use the "set" method to set the selected index to 0. Which is crazy.
Anyone know of a good way around this? other than setting a bool that causes the model to ignore the first set command it receives?
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
I haven't run into this, but here's my theory about what's happening:
1. The array controller gets the observed property of the model — but the table isn't interested in this yet.
2. The table, in its setup, chooses a default selection index of 0.
3. The table setting its selection index causes the value to be pushed down the bindings, leaving your model's value as 0 as well.
Assuming I'm right, the simplest workaround would be [tableView selectRowIndexes:model.selectedIndexes byExtendingSelection:NO].
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Apr 2004
Status:
Offline
|
|
I like your theory. it sounds about like what I was expecting. I'm not sure I like your solution, if simply for the reason that I'm trying to make it so the model class doesn't even need to know it's being watched. (i.e. doesn't have to tell the table view anything). Maybe I'm being over-optimistic though. I dunno.
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Oh, I meant that to be in the controller. The model obviously shouldn't know there's an NSTableView involved.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Apr 2004
Status:
Offline
|
|
ah yes, I suppose I could do that. I'd have to subclass the standard NSArrayController to do that, but I suppose it could be done...
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|