In Aaron Hillegass Cocoa for Mac OS X, Chapter 9, the section “Start editing when pasting,” he explains how to do this. What confused me was that he did a bunch of other things. Here is a complete list of codes:
- (IBAction)createEmployee:(id)sender
{
NSWindow *w = [tableView window];
BOOL editingEnded = [w makeFirstResponder:w];
if (!editingEnded) {
NSLog(@"Unable to end editing");
return;
}
NSUndoManager *undo = [self undoManager];
if ([undo groupingLevel]) {
[undo endUndoGrouping];
[undo beginUndoGrouping];
}
Person *p = [employeeController newObject];
[employeeController addObject:p];
[p release];
[employeeController rearrangeObjects];
NSArray *a = [employeeController arrangedObjects];
int row = [a indexOfObjectIdenticalTo:p];
NSLog(@"starting edit of %@ in row %d", p, row);
[tableView editColumn:0
row:row
withEvent:nil
select:YES];
}
I have two questions regarding this:
1) How do you know that you should do all this? Is there a checklist or something in the Apple document? An experience?
2) Doesn't that destroy the whole purpose of the array controller if you still need to rewrite all the methods yourself?
EDIT: I basically wonder how he knew to put these lines: (since everything else is pretty solid and obvious)
NSWindow *w = [tableView window];
BOOL editingEnded = [w makeFirstResponder:w];
if (!editingEnded) {
NSLog(@"Unable to end editing");
return;
}
NSUndoManager *undo = [self undoManager];
if ([undo groupingLevel]) {
[undo endUndoGrouping];
[undo beginUndoGrouping];
}