• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSArrayController selection bug?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSArrayController selection bug?


  • Subject: Re: NSArrayController selection bug?
  • From: Henrik Wittland <email@hidden>
  • Date: Mon, 10 Nov 2003 23:59:44 +0100

Am 10.11.2003 um 21:12 schrieb Jesse Grosjean:

I have an NSArrayController that is bound to a NSMutableArray in my model. And I have a NSTableView that's bounds to this NSArrayController. Everything is working and seems to be set up correctly for the basic cases.

But an exception is thrown when the last item in the table view is selected and I remove an item from my model's mutable array directly (but in a KVC compliant way), instead of going through the NSArrayControllers "remove" action. You can duplicate the problem by adding the following method to the MyDocument class that comes with the ControllerPlay example program that ships with 10.3. And then connect a button action to it.

- (IBAction)modelRemove:(id)sender {
NSMutableArray *c = [self contentArray];
[c removeObjectAtIndex:0];
[self setContentArray:c];
}

This code is not KVC compliant.

Run the example. Insert an item or two into the table, and then after making sure that the last item is selected click your new "remove from model" button and you will get the error.

What I think is happening is that when the NSArrayController gets the KVO notification that the array has changed it calls "selectedObjects" in itself. And it uses it's stored "_selectedIndexes" to find those objects, but unfortunately the "_selectedIndexes" variable still contains the index of the last selected object in the table view (that is now removed), and so when it asks for this index from the model array it overruns the array.

Is this a known bug?
Don't know. You should file a bugreport to apple. It is a BUG.

Does anyone have an idea for a workaround?
Yes.

- (IBAction)modelRemove:(id)sender {
NSMutableArray *c = [NSMutableArray arrayWithArray:[self contentArray]];
[c removeObjectAtIndex:0];
[self setArray:c];
}

I think in your case this workaround should help but if you would declare your interface like this :

@interface MyDocument : NSDocument {
...
NSArray *contentArray;
...
}
...
- (NSArray *)contentArray;
- (void)setContentArray:(NSArray *)array;
...
@end

It's not only a workaround but the right way to go.

So the bug is only present with mutable toManyRelationships. Immutable toManyRelationships work as expected.

Regards,
Henrik
_______________________________________________
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.

  • Follow-Ups:
    • Re: NSArrayController selection bug?
      • From: mmalcolm crawford <email@hidden>
References: 
 >NSArrayController selection bug? (From: Jesse Grosjean <email@hidden>)

  • Prev by Date: Re: NSArrayController selection bug?
  • Next by Date: Re: itunes for windows HOWTO ???
  • Previous by thread: Re: NSArrayController selection bug?
  • Next by thread: Re: NSArrayController selection bug?
  • Index(es):
    • Date
    • Thread