Re: Out-of-bounds error when removing entry from NSForm
Re: Out-of-bounds error when removing entry from NSForm
- Subject: Re: Out-of-bounds error when removing entry from NSForm
- From: Sam Stigler <email@hidden>
- Date: Wed, 16 May 2007 00:57:11 +1000
Thanks George! Your while loop worked; and something in your first
sentence made me think that maybe my problem was that my "for" loop
was counting the wrong way. I reversed it (see code below), and now
it works. So for anybody reading this in the archive who is having a
similar problem with NSForm, try reversing your "for" loop and see if
that does the trick. I guess that's make sense, because in a form
entries, indexed 0 to 3 for example, it makes sense that the form
would remove index 3 before it removed index 0. Next time I should
really draw it out or something...
int numrows = [metadataForm numberOfRows];
int curRow = numrows-1;
for (curRow; curRow >= 0; curRow--) {
[metadataForm removeEntryAtIndex:curRow];
}
-Sam
http://www.stigler.org/sam/wordpress
On May 16, 2007, at 12:14 AM, George Orthwein wrote:
Just a guess... could it be that in your loop, as you remove rows,
the total row count reduces each loop so that curRow eventually
becomes out of bounds? You can remove the highest index first and
count down or perhaps a while loop like this would work:
while ([metadataForm numberOfRows])
{
[metadataForm removeEntryAtIndex:0];
}
I would stick with removeEntryAtIndex since the Form guide says to
use it:
http://developer.apple.com/documentation/Cocoa/Conceptual/Form/
Tasks/ManagingFormEntries.html
The reference for removeEntryAtIndex says "If the specified index
is invalid, this method does nothing." so I wonder why that was
giving you an error too. Maybe "invalid" does not include out of
bounds?
Hope that helps,
George
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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