Re: 2nd table array linked to 1st table selection, updating
Re: 2nd table array linked to 1st table selection, updating
- Subject: Re: 2nd table array linked to 1st table selection, updating
- From: Keary Suska <email@hidden>
- Date: Fri, 21 Oct 2011 11:10:06 -0600
On Oct 21, 2011, at 10:16 AM, Chris Paveglio wrote:
> My app watches several folders (and subfolders) on our file servers, and counts and displays the files in those folders.
> I have a class for the folder data that contains the count from 3 subfolders (ints) and then an array of file names of the files from one of the subfolders.
> There are 8 folders that are watched, and those 8 items are in an array. I have a table view that has columns for the integer values from the class object. Then there is a second table where I show the file names when the user selects a row from the first table.
> I have both these tables set up using bindings and array controllers. The first table is straight forward setup. The second one's content array is bound to the first array controller. The controller key is "selection" and the model key path is the name of the array in the class object.
> The second table shows up fine, and it's content changes when I change the selection on my first table.
> But when the contents of the folder changes and the app recalculates the data, I get an error that *** -[NSCFArray objectAtIndex:]: index (3) beyond bounds (3)
> This only occurs when the first table has a selection, and I understand (probably) that it's because the second table is based on the first, and that the data for the 2nd table is changing in a non-KVC compliant kind of way. I'm not telling the 2nd array controller to remove or reset the values in the class object's array, I am just directly removing all the objects from class object array, then re-adding the newly scanned file names into the array.
> My workaround is, in code, the first table is deselected, the values are all updated, and then the originally selected row is reselected. This makes the display function and update properly.
As you think, you need to update the "primary" array in a KVC/KVO compliant way. That is always the best way to update objects that are observed/bound. The simplest way is to first get the mutable proxy using -[object mutableArrayValueForKey:]. Any changes you make to the returned array will be propagated appropriately.
Best,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden