Re: Binding Blues
Re: Binding Blues
- Subject: Re: Binding Blues
- From: Garrett Kunimura <email@hidden>
- Date: Thu, 29 Jul 2004 22:41:39 -0700 (PDT)
>
My application controller is holding an array
_groups. Each group in
>
the _groups array has a contents array which holds
all the objects
>
stored inside the group.
>
So when I went to remove an object from one of my
groups I simply did
>
this:
>
[self willChangeValueForKey:@"groups"];
>
[[[[self groups] objectAtIndex:[groupTable
selectedRow]] contents]
>
removeObjectAtIndex:[contentsTable selectedRow]];
>
[self didChangeValueForKey:@"groups"];
>
[...]
>
Whenever I remove the last object in the contents I
get an error:
>
*** -[NSCFArray objectAtIndex:]: index (0) beyond
bounds
I had this problem before: it has to do with the
selection state of the controller when you are
deleting objects from the array. There are two ways
to fix this problem. The first solution is to uncheck
the "Preserves Selection" attribute of your array
controller. If you do this, the controller will
automatically set the selection to NSNotFound. If you
decide you want to preserve some sort of selection,
then you have to move it's position yourself in code.
If you don't, you will get that array out of bounds
error as soon as the index does not exist. Here is a
sample of what you can do:
if (![peopleController canSelectPrevious])
{
[peopleController setSelectionIndex:NSNotFound];
}
else
{
[peopleController selectPrevious:self];
}
That's all there is too it.
Garrett
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail
_______________________________________________
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.