Re: NSTableView or NSArray Troubles...
Re: NSTableView or NSArray Troubles...
- Subject: Re: NSTableView or NSArray Troubles...
- From: matt neuburg <email@hidden>
- Date: Wed, 11 Dec 2002 12:59:45 -0800
On Wed, 11 Dec 2002 11:48:46 -0800, Ian Gillespie <email@hidden> said:
>
OK, I have a document based app which was working fine for a long time
>
when I noticed that if I tried to delete the last row in the table I
>
would get a -[NSCFArray objectAtIndex:]: index (2) beyond bounds (2)
>
error. This used to not happen, the error occurred in my method when
>
after I remove the object from my array and I call [tableView
>
reloadData].
>
>
Now, when I try to open a new document I get a -[NSCFArray
>
objectAtIndex:]: index (0) beyond bounds (0). However, if during my
>
init method in my NSDocument subclass I add an object to the array
>
everything is fine, until of course I try to delete the object from the
>
table view. What I can't figure out is that everything seemed to be
>
working fine and now it isn't
A bug in your datasource code has been revealed. Fix it. When your table is asked the first of the Two Big Questions ("how many rows ya got there, bub?") you need to start by checking whether you've any data at all. If you don't, the answer needs to be zero.
Something similar is happening when you delete the object. You're answering the first Big Question wrong (your answer is one larger than the number of items in your data), so when Cocoa asks the second Big Question your code looks for an item in your array that isn't there. Or perhaps the bug is in the second Big Question; you need to introduce some bounds checking here, perhaps, to make sure you aren't trying to supply an item that isn't there. m.
matt neuburg, phd = email@hidden,
http://www.tidbits.com/matt
pantes anthropoi tou eidenai oregontai phusei
Subscribe to TidBITS! It's free and smart.
http://www.tidbits.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.