我需要知道用户何时完成在NSTableView中编辑单元格.该表包含所有用户的日历(从CalCalendarStore获取),因此为了保存用户的更改,我需要通知CalCalendarStore更改.但是,在用户完成编辑后我找不到任何被调用的东西 - 我猜想在表的委托中会有一个方法,但我只看到一个在编辑开始时调用,而不是在编辑结束时调用.
Mil*_*lly 14
NSTableView通过使用NSNotificationCenter或使用NSControl方法,您可以在不进行子类化的情况下实现相同的结果.请在此处查看Apple文档:
http://developer.apple.com/library/mac/#qa/qa1551/_index.html
它只有几行代码,对我来说非常合适.
如果你可以是delegate的NSTableView,你只需要实现的方法
- (void)controlTextDidEndEditing:(NSNotification *)obj { ... }
Run Code Online (Sandbox Code Playgroud)
事实上,NSTableView是delegate所述的NSControl它包含的元件,并且将那些方法调用到其delegate(但是也有一些有用的其它方法)
否则,使用NSNotificationCenter:
// where you instantiate the table view
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(editingDidEnd:)
name:NSControlTextDidEndEditingNotification object:nil];
// somewhere else in the .m file
- (void)editingDidEnd:(NSNotification *)notification { ... }
// remove the observer in the dealloc
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:NSControlTextDidEndEditingNotification object:nil];
[super dealloc]
}
Run Code Online (Sandbox Code Playgroud)
子类 NSTableView 并覆盖 textDidEndEditing: (确保调用 super 的实现)。
这只会由文本字段 NSTextFieldCell 或 NSComboBoxCell 调用(但仅当通过键入更改值时,而不是通过从组合菜单中选择值时)。
| 归档时间: |
|
| 查看次数: |
5184 次 |
| 最近记录: |