Skip navigation.
 
mlForce arrayController to remove immediately?
FROM : Justin Hawkwood
DATE : Sat Feb 16 21:31:56 2008

I have an array controller bound in the NIB to a Core Data Entity, and 
a function to remove the selected item (from tableview) through that 
array controller.  The problem is that I want to rescan the array 
controller to set some other variables based on the remaining items in 
the array, but since the "remove" function is delayed, the item for 
removal is still in the array until the next run loop.

From the Apple doc for NSArrayController:

> Special Considerations
> Beginning with Mac OS X v10.4 the result of this method is deferred 
> until the next iteration of the runloop so that the error 
> presentation mechanism can provide feedback as a sheet.
>

My functions:

- (IBAction)removeProfileEntry:(id)sender
{
   [profileEntryController removeObjects:[profileEntryController 
selectedObjects]];
   [self updateTime];
//    [NSTimer scheduledTimerWithTimeInterval:0.01 target:self 
selector:@selector(updateAllStats)
//        userInfo:nil repeats:NO];
}

- (void) updateTime
{
   // "profile" is a subset from profileEntryController
   NSMutableSet *profile = [[[diveArrayController selectedObjects] 
objectAtIndex:0] valueForKey:@"profileData"];
   NSSet *aSet = [profile valueForKey:@"time"];
   if ((aSet != nil) && ([aSet count] != 0)) {
       float max = 0.0;
       NSEnumerator *enumerator = [aSet objectEnumerator];
       id value;
       while ((value = [enumerator nextObject])) {
           if ([value floatValue] > max) max = [value floatValue];
       }
       [[[diveArrayController selectedObjects] objectAtIndex:0] setValue:
[NSNumber numberWithFloat:max]
           forKey:@"diveTime"];
   }
}

Run as is, the removed object is still included when updateTime is 
called.  If I use the timer instead, in removeProfileEntry, then 
updateTime functions properly, but it creates a separate undo event, 
which I don't want.

How do I force the removal to take place immediately, or is there a 
notification I can watch for that tells me the removal has completed, 
and then run the updateTime method?

~ Justin

Related mailsAuthorDate
mlForce arrayController to remove immediately? Justin Hawkwood Feb 16, 21:31
mlRe: Force arrayController to remove immediately? Ben Lachman Feb 17, 03:29
mlRe: Force arrayController to remove immediately? Dave Hayden Feb 26, 20:51
mlRe: Force arrayController to remove immediately? Justin Hawkwood Feb 26, 23:21