如何使用“编辑” NSTableView 的事件
在 NStableViewDelegate 内部,我使用工作表窗口开始编辑操作,如下所示:
- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex {
editEntity = [[contractsAC selectedObjects] objectAtIndex:0];
needsWriteToArrayController = FALSE;
[self beginSheet];
return NO;
}
- (void) beginSheet {
[NSApp beginSheet:contractEditWindow
modalForWindow:mainWindow
modalDelegate:nil
didEndSelector:NULL
contextInfo:nil
];
}
如果双击表格单元格,事情将按预期运行:工作表出现,我可以编辑其输入。
如果选择表格单元格并按返回键,则事情往往会被连接:工作表出现,但返回键事件被转发到工作表。反过来,工作表的默认“保存”按钮被触发 - 并使工作表消失。太糟糕了,没有机会编辑;-)
我应该在 shouldEditTableColumn: 方法中使用当前的关键事件吗?如果是的话,我该怎么办?
Inside a NStableViewDelegate, I use a sheet window to begin a edit operation like this:
- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex {
editEntity = [[contractsAC selectedObjects] objectAtIndex:0];
needsWriteToArrayController = FALSE;
[self beginSheet];
return NO;
}
- (void) beginSheet {
[NSApp beginSheet:contractEditWindow
modalForWindow:mainWindow
modalDelegate:nil
didEndSelector:NULL
contextInfo:nil
];
}
If I double-click a table cell, things behave as expected: The sheet appears and I'm able to edit its inputs.
If a table cell is selected and I press the return key, things tend to be wired: The sheet appears, but the return key event gets forwarded to the sheet. In turn, the default SAVE button of the sheet gets fired - and makes the sheet disappear. Too bad, no chance to edit ;-)
Should I consume the current key event inside the shouldEditTableColumn: method? If yes, how could I?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试使用
-performSelector:withObject:afterDelay:
推迟工作表呈现。添加一个用于设置和显示工作表的私有方法,并为其指定0.0
的延迟。它将在运行循环中稍后安排,从而使按键有机会传播。You could try deferring sheet presentation with
-performSelector:withObject:afterDelay:
. Add a private method that sets up and presents the sheet, and give it a delay of0.0
. It'll be scheduled slightly later on the run loop, giving the keypress a chance to propagate.