I tested a new build of an app today and found that, all of a sudden, clicking 
the "+" button for a table view adds a new object but no longer selects it.  
It's a conventional design with the "+" button targetting the -add: method of 
an array controller instantiated in the nib, and the table bound to the array 
controller.  I inspected the array controller's Attributes, but "Select 
Inserted Objects" definitely has a big fat checkmark in the box.

Our buddy 'PCWiz' reported the same issue -- "now I have another problem (once 
again, out of the blue)" -- a few months ago, but the thread got slapped 
because Snow Leopard was under NDA at the time:

http://lists.apple.com/archives/Cocoa-dev/2009/Aug/msg00962.html

Well, I had an NSArrayController subclass handy, so I tried overriding 
-selectsInsertedObjects to return YES but that did not help.  I fixed it with 
this kludge:

- (void)add:(id)sender {
    [super add:sender] ;
    // Does not work without delay.
    [self performSelector:@selector(selectLastObject)
               withObject:nil
               afterDelay:0.0] ;
}

- (void)selectLastObject {
    if ([self selectsInsertedObjects]) {
        NSArray* arrangedObjects = [self arrangedObjects] ;
        NSInteger nObjects = [arrangedObjects count] ;
        if (nObjects > 0) {
            [self setSelectionIndex:nObjects-1] ;
        }
    }
}

Has anyone else had trouble recently with NSArrayController's "Select Inserted 
Objects"?

Sincerely,

Jerry Krinock


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please 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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to