【问题标题】:NSTableView cell editing: where to perform post-editing operations?NSTableView 单元格编辑:在哪里进行后期编辑操作?
【发布时间】:2013-10-02 10:38:44
【问题描述】:

我通过直接选择单元格 (NSTextFieldCell) 并编辑其中的文本来修改 NSTableView 的源数据。

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

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

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

谢谢

【问题讨论】:

    标签: macos cocoa nstableview


    【解决方案1】:

    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:row: 数据源 协议方法。这种方法类似于 tableView:objectValueForTableColumn:row:,提供数据 表视图,而不是要求您返回一个值 指定的行和列,它为该行提供新值 和细胞

    【讨论】:

      【解决方案2】:

      让谷歌搜索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;
      }
      

      您可以这样做,因为NSTableView 的单元格是NSTextFieldCells;

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-01-08
        • 1970-01-01
        • 1970-01-01
        • 2012-02-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-03-18
        相关资源
        最近更新 更多