Simon Fell > Its just code > Tiger Table Editing

Friday, November 2, 2007

As I mentioned yesterday, the behavior of NSTableView changes in Leopard, pressing enter after editing a cell no longer starts editing the cell below it. There's some hints in the release notes, and on the Cocoa-dev mailing list, seems you have to subclass NSTableView, here's what i ended up with. Hopefully this'll save someone some time.

@interface MyTableView : NSTableView {
}
@end

@implementation MyTableView

- (void)textDidEndEditing:(NSNotification *)aNotification {
	if ([[[aNotification userInfo] objectForKey:@"NSTextMovement"] intValue] == NSReturnTextMovement) {
		int row = [self editedRow] + 1;
		int col = [self editedColumn];
		NSMutableDictionary *ui = [NSMutableDictionary dictionaryWithDictionary:[aNotification userInfo]];
		[ui setObject:[NSNumber numberWithInt:NSDownTextMovement] forKey:@"NSTextMovement"];
		aNotification = [NSNotification notificationWithName:[aNotification name] object:[aNotification object] userInfo:ui];
		[super textDidEndEditing:aNotification];
		if (row < [self numberOfRows]) {
			[self selectRow:row	byExtendingSelection:NO];
			[self editColumn:col row:row withEvent:nil select:YES];
		}
	} else {
		[super textDidEndEditing:aNotification];
	}
}

@end