On 17 Aug 2012, at 9:15 PM, Erik Stainsby <[email protected]> wrote:

> I have a view-based table in which there are four distinct row types, 
> representing distinct object types which may appear. The tableRowViews are in 
> the nib and represented in the code here as xxxCellView entities. 
> 
> 
> - (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row {
> 
>       id obj = [_content objectAtIndex:row];

Notice that here you call objectAtIndex:, I assume from within your class 
RSTableController.

> 2012-08-17 18:51:52.767 RSSuperContactsX[24075:303] *** -[__NSArrayM 
> objectAtIndex:]: index 6 beyond bounds [0 .. 5]

Notice that the system finds you have passed an illegal index to 
objectAtIndex:...

>       2   CoreFoundation                      0x00007fff900455dc -[__NSArrayM 
> objectAtIndex:] + 252
>       3   RSSuperContactsX                    0x00000001000030f5 
> -[RSTableController tableView:heightOfRow:] + 101

... from within your -[RSTableController tableView:heightOfRow:].

> My expectation is that I ought to be able to clear the table (iterating 
> through the rows and applying -removeRowsAtIndexes:withAnimation:  to discard 
> the present rowViews, and start clean with the next record to be displayed, 
> generating new rowViews as needed (because the number of component elements 
> (phone numbers/email addresses/etc) will vary from one record to the next). 

Not a good expectation, if you are altering a collection while you are 
iterating it. (You imply that's what you're doing, but it's not clear.) Doing 
so leaves the collection in an inconsistent condition, and anything that 
depends on the collection will have invalid data. (But see next paragraph.) The 
table view might, for instance, try to index to a row for which the backing 
data no longer exists.

UNLESS: You bracket your alterations to the table with -beginUpdates and 
-endUpdates.

> I have no iterator code running at the time this error occurs, so I suspect I 
> have failed to correctly setup some aspect of the tableView/rowView 
> mechanics.  Does anything suggest itself to anyone ? 

The table view itself is iterating your rows.


By the way, heed the documentation for -beginUpdates :

> Note that these methods should be called to reflect changes in your model; 
> they do not make any underlying model changes.



        — F


_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to