我想在编辑时更改NSTableView单元格中显示的值。我的要求如下: 最初我输入的单元格值为234.5678978,编辑后值被四舍五入为0的十进制精度(即235)。我的要求是,当我可以点击那个单元格时,它应该显示我的值到一定的小数精度,比如5精度,在本例中为234.56790)。我怎样才能实现这个功能。 我试图捕捉双击编辑NSTableView的的细胞的作用:编辑时更改NSTableView单元格值
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(editingDidEnd:)
name:NSControlTextDidEndEditingNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(editingDidBegin:)
name:NSControlTextDidBeginEditingNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(editingDidChange:)
name:NSControlTextDidChangeNotification object:nil];
- (void)editingDidEnd:(NSNotification *)notification
{
NSLog(@"text editing fisnished");
}
- (void)editingDidBegin:(NSNotification *)notification
{
NSLog(@"text is being edited");
}
- (void)editingDidChange:(NSNotification *)notification
{
NSLog(@"text was being changed");
}
但只有editingDidEnd
叫上标签了,而且从来没有叫其他两种方法。
'validateProposedFirstResponder'没有在我的NSTableView子类中调用。 – triandicAnt 2014-10-22 11:45:24
确保在表格视图的IB属性中取消选中“拒绝第一响应者”。另请注意,“validateProposedFirstResponder”在SDK10.7以下目标上不可用 – 2014-10-22 12:38:51
我在“if”条件下编辑了代码部分。 通过这种方式可以确保您仅捕获所选单元格中的鼠标点击,从而避免干扰正常的tableview超类的行为。 希望它有帮助。 – 2014-10-23 10:51:17