One Quickie

Preventing the return key from editing the next cell (NSTableView->General)
The default tableview behavior, when editing a row, is to move the field editor to the next cell when the user commits editing using the Return key. If you want Return to commit the editing and dismiss the field editor, subclass NSTableView and add this:
- (void) textDidEndEditing: (NSNotification *) notification
    NSDictionary *userInfo;
    userInfo = [notification userInfo];

    NSNumber *textMovement;
    textMovement = [userInfo objectForKey: @"NSTextMovement"];

    int movementCode;
    movementCode = [textMovement intValue];

    // see if this a 'pressed-return' instance

    if (movementCode == NSReturnTextMovement) {
        // hijack the notification and pass a different textMovement
        // value

        textMovement = [NSNumber numberWithInt: NSIllegalTextMovement];

        NSDictionary *newUserInfo;
        newUserInfo = [NSDictionary dictionaryWithObject: textMovement
                                    forKey: @"NSTextMovement"];

        notification = [NSNotification notificationWithName:
                                           [notification name]
                                       object: [notification object]
                                       userInfo: newUserInfo];

    [super textDidEndEditing: notification];

} // textDidEndEditing

borkware home | products | miniblog | rants | quickies | cocoaheads
Advanced Mac OS X Programming book