Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Bindings and selected index

Bindings and selected index
Thread Tools
Dedicated MacNNer
Join Date: Apr 2004
Status: Offline
Reply With Quote
Dec 22, 2007, 12:37 AM
 
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
Reply With Quote
Dec 22, 2007, 02:38 AM
 
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
Reply With Quote
Dec 22, 2007, 02:56 AM
 
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
Reply With Quote
Dec 22, 2007, 01:32 PM
 
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
Reply With Quote
Dec 22, 2007, 03:59 PM
 
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...
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:36 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2