NSTableView命令选项卡在编辑时从行跳到行 [英] NSTableView hit tab to jump from row to row while editing
问题描述
我有一个NSTableView。编辑时,如果我打标签页,它会自动跳转到下一列。这是太棒了,但是当我在编辑最后一列中的字段时,我打标签,我想要焦点跳到NEXT行的第一列。
I've got an NSTableView. While editing, if I hit tab it automatically jumps me to the next column. This is fantastic, but when I'm editing the field in the last column and I hit tab, I'd like focus to jump to the first column of the NEXT row.
任何建议?
感谢Michael为起始代码,这是非常接近,结束了工作!这里是我使用的最终代码,希望它将有助于别人:
Thanks to Michael for the starting code, it was very close to what ended up working! Here is the final code that I used, hope it will be helpful to someone else:
- (void) textDidEndEditing: (NSNotification *) notification {
NSInteger editedColumn = [self editedColumn];
NSInteger editedRow = [self editedRow];
NSInteger lastColumn = [[self tableColumns] count] - 1;
NSDictionary *userInfo = [notification userInfo];
int textMovement = [[userInfo valueForKey:@"NSTextMovement"] intValue];
[super textDidEndEditing: notification];
if ( (editedColumn == lastColumn)
&& (textMovement == NSTabTextMovement)
&& editedRow < ([self numberOfRows] - 1)
)
{
// the tab key was hit while in the last column,
// so go to the left most cell in the next row
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:(editedRow+1)] byExtendingSelection:NO];
[self editColumn: 0 row: (editedRow + 1) withEvent: nil select: YES];
}
}
推荐答案
子类UITableView并添加代码来捕获textDidEndEditing调用。
Subclass UITableView and add code to catch the textDidEndEditing call.
然后,您可以根据以下内容决定要执行的操作:
You can then decide what to do based on something like this:
- (void) textDidEndEditing: (NSNotification *) notification
{
NSDictionary *userInfo = [notification userInfo];
int textMovement = [[userInfo valueForKey:@"NSTextMovement"] intValue];
if ([self selectedColumn] == ([[self tableColumns] count] - 1))
(textMovement == NSTabTextMovement)
{
// the tab key was hit while in the last column,
// so go to the left most cell in the next row
[yourTableView editColumn: 0 row: ([self selectedRow] + 1) withEvent: nil select: YES];
}
[super textDidEndEditing: notification];
[[self window] makeFirstResponder:self];
} // textDidEndEditing
此代码未经测试...没有保证...等等。你可能需要移动[超级textDidEndEditing:]调用最右边选项卡单元格的情况。但希望这将帮助你到终点线。让我知道!
This code isn't tested... no warranties... etc. And you might need to move that [super textDidEndEditing:] call for the tab-in-the-right-most-cell case. But hopefully this will help you to the finish line. Let me know!
这篇关于NSTableView命令选项卡在编辑时从行跳到行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!