I’m getting a warning in the following method:
- (void)tableView:(NSTableView *)aTableView
setObjectValue:(id)anObject
forTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
NSString *identifier = [aTableColumn identifier];
Person *person = [employees objectAtIndex:rowIndex];
NSUndoManager *undo = [self undoManager];
[[undo prepareWithInvocationTarget:self] tableView:aTableView setObjectValue:[person valueForKey:identifier] forTableColumn:aTableColumn row:rowIndex];
if(![undo isUndoing])
{
[undo setActionName:@"Edit Person"];
}
[person setValue:anObject forKey:identifier];
[tableView reloadData];
}
I’m trying to implement undo so I figure I would call the same method and just pass the old value. The error I’m getting is “warning: multiple methods named ‘-tableView:setObjectValue:forTableColumn:row:’ found”. Any idea why?
The method on NSTableViewDataSource is declared as:
Your method uses
intas the type of therowIndexvariable. Change that toNSIntegerand all will be fine.The underlying issue is that Objective-C does not support co-variance or contra-variance in method argumentation, leading to the warning.
Note also that you are colluding data model with view layer. Undo in this fashion is going to be very very tricky; if you don’t also manage the undo stack in the context of every sort of the table and/or addition/removal of rows, undo is going to apply the value to the wrong row.
You would be far better off reworking your app such that you have a proper separation of model view and controller.