2013-10-02 59 views
0

我通过直接选择单元格(NSTextFieldCell)并编辑其中的文本来修改NSTableView的源数据。NSTableView单元格编辑:在哪里执行后期编辑操作?

我需要在编辑单元格之前和之后对单元格执行一些操作。 我在编辑之前进行这样的操作:

- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex 

但我在哪里可以执行的操作后编辑?

感谢

回答

1

让谷歌搜索NSTableView的编辑变化,你会得到很多详细解答的。

要长话短说:使用(部分)以下(以及类似)的委托方法:

- (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; 
} 

你可以这样做,因为NSTableView的单元格是NSTextFieldCell s;

4

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Protocols/NSTableDataSource_Protocol/index.html#//apple_ref/occ/intfm/NSTableViewDataSource/tableView:setObjectValue:forTableColumn:row

- (void)tableView:(NSTableView *)aTableView 
    setObjectValue:(id)anObject 
    forTableColumn:(NSTableColumn *)aTableColumn 
       row:(NSInteger)rowIndex 

引自:https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/TableView/PopulatingCellTables/PopulatingCellTables.html

让应用程式编辑基于的NSCell表视图中的内容,你 实现的tableView:setObjectValue:forTableColumn:行:数据源 协议方法。此方法类似于 tableView:objectValueForTableColumn:row :,它为表视图提供 的数据,但不是请求您为指定的行和列返回 的值,而是为该行提供新值 以及cell