I’ve been having a bit of trouble with this one – but I hadn’t gone with the createNewEmployee example verbatim, more used it as a loose guide. It seemed that there should be a way, in the spirit of the data object model and binding lesson of this chapter to get this one done without going back to the manual way of doing things.
This either almost works, or is way off base, and I’m not sure which. Everything is bound properly (I think), but instead of the createCar mentioned elsewhere, I have the following, bound to the Add button:
// find the index of the object just added
NSUInteger row = [tableView selectedRow];
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:row];
// insert a new row ## making a copy of the previous row?!? ##FIX
// begin the edit in the first column
NSLog(@"starting edit of new car in row %lu", row);
On running the app, a new row gets created, everything shifts down, and the new row is in edit mode, but the new row is already filled with the data of the previous row. I still haven’t wrapped my head round Apple’s documentation, so I can’t quite tell if the problem is that I’m passing something incorrectly or just plain trying to do it wrong…
It just seemed that, since the tableView already exists as a proxy object and it already has methods, I could maybe use that instead of creating new objects?
Also, assuming this could be made to work at all, since the existing functionality in the tableView & arrayController bindings and the NSManagedObjectModel are magically handling the undo stack, wouldn’t this forego having to do that manually as well? (I can’t tell, since the duplicate rows are colliding right now.)
I’m going to dig into this a bit more, but if someone could chime in and tell me whether I’m chasing wild geese, I’d really appreciate it!