NSTableView我通过直接选择单元格 ( NSTextFieldCell) 并编辑其中的文本来修改 a 的源数据。
我需要在编辑单元格之前和之后对单元格执行一些操作。我在编辑之前执行了这样的操作:
- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
但是我可以在哪里执行编辑后的操作?
谢谢
NSTableView我通过直接选择单元格 ( NSTextFieldCell) 并编辑其中的文本来修改 a 的源数据。
我需要在编辑单元格之前和之后对单元格执行一些操作。我在编辑之前执行了这样的操作:
- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
但是我可以在哪里执行编辑后的操作?
谢谢
- (void)tableView:(NSTableView *)aTableView
setObjectValue:(id)anObject
forTableColumn:(NSTableColumn *)aTableColumn
row:(NSInteger)rowIndex
For your app to edit the content of an NSCell-based table view, you implement the tableView:setObjectValue:forTableColumn:row: data source protocol method. This method is similar to tableView:objectValueForTableColumn:row:, which provides the data for the table view, but instead of requesting that you return a value for the specified row and column, it provides the new value for that row and cell
让google搜索nstableview edit change,你会得到很多详细的答案。
简而言之:使用(某些)以下(和类似的)委托方法:
- (void)controlTextDidEndEditing:(NSNotification *)obj
- (void)controlTextDidChange:(NSNotification *)aNotification
- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
并测试它们以显示适合您的应用程序的内容:
- (void)controlTextDidEndEditing:(NSNotification *)obj
{
NSDictionary *userInfo = [obj userInfo];
NSTextView *aView = [userInfo valueForKey:@"NSFieldEditor"];
NSLog(@"controlTextDidEndEditing %@", [aView string] );
}
- (void)controlTextDidChange:(NSNotification *)aNotification
{
NSDictionary *userInfo = [aNotification userInfo];
NSTextView *aView = [userInfo valueForKey:@"NSFieldEditor"];
NSLog(@"controlTextDidChange >>%@<<", [aView string] );
}
- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
{
NSLog(@"control: textShouldEndEditing >%@<", [fieldEditor string] );
return YES;
}
您可以这样做,因为 s; 的单元格NSTableView是NSTextFieldCells;