• 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
NSArrayController causes NSRangeException when removing all objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSArrayController causes NSRangeException when removing all objects


  • Subject: NSArrayController causes NSRangeException when removing all objects
  • From: Jonathan Paisley <email@hidden>
  • Date: Tue, 9 Mar 2004 13:10:31 +0000

Hello Cocoa bindings experts,

I am making use of an NSArrayController to bind the contents of an NSMutableArray to a table view. The table view is read-only, and its contents are populated dynamically from the results of a command line task.

I have a Refresh button which is intended to clear the results and re-execute the command line tool. I am using manual change notification and using the following method to clear the results array and notify the controller:

- (void)removeAllResults {
NSIndexSet *indexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0,[_results count])];

[self willChange:NSKeyValueChangeRemoval valuesAtIndexes:indexes forKey:@"results"];
[_results removeAllObjects];
[self didChange:NSKeyValueChangeRemoval valuesAtIndexes:indexes forKey:@"results"];
}

Unfortunately, if I do this when there is a row selected, an exception is raised. Here follows a traceback after putting a breakpoint on -[NSException raise]:

#0 0x90a5cdc8 in -[NSException raise] ()
#1 0x90a5cdb4 in +[NSException raise:format:] ()
#2 0x909f14f4 in -[NSCFArray objectAtIndex:] ()
#3 0x931d29b4 in -[NSArrayController selectedObjects] ()
#4 0x931d1be0 in -[NSArrayController setContent:] ()
#5 0x931dd51c in -[NSArrayDetailBinder _refreshDetailContentInBackground:] ()
#6 0x90a9605c in -[NSObject(NSKeyValueObserverNotification) didChange:valuesAtIndexes:forKey:] ()
#7 0x04eeacd0 in -[SCSubversionStatusUI removeAllResults] (self=0x582a700, _cmd=0x4ef13bc)

An uncaught exception was raised
*** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)
*** Uncaught exception: <NSRangeException> *** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)

I had hoped that the controller would automatically deselect the row that was getting removed. Instead, I have manually added:

[_arrayController setSelectionIndexes:[NSIndexSet indexSet]];

to deselect everything before removing the o bjects.

My question is this: am I going about things entirely the wrong way here, or is this a small bug in NSArrayController?

Many thanks.
_______________________________________________
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.


  • Prev by Date: Re: OK, but what do 'attributes' look like?
  • Next by Date: Re: NSMutableArray morphs itself into an NSArray?
  • Previous by thread: Re: OK, but what do 'attributes' look like?
  • Next by thread: Convert Charatcers
  • Index(es):
    • Date
    • Thread