当我将自定义视图用作基于视图的NSTableView的单元格时,自定义视图会略微低于表行。当我单击它时,而不是影响元素(例如文本字段)自定义视图,表行会被选中(并突出显示)。我必须重新单击以选择文本字段。
- (NSView*)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
NSLog(@"We are creating views!");
NSTableCellView *newView;
newView = [tableView makeViewWithIdentifier:@"PostCell" owner:self];
NSTextField *newTextField = [[NSTextField alloc] init];
[newView addSubview:newTextField];
return newView;
}
当我根据NSTableView - Disable Row Selection禁用行选择时,就不会有选择了。
- (BOOL)selectionShouldChangeInTableView:(NSTableView *)tableView {
return NO;
}
但是我仍然无法直接选择文本框。更糟糕的是,我甚至不能使用鼠标选择它。只能使用键盘上的 tab
键。
似乎有一些东西在它的上方。但是它是界面生成器中显示的“表列”吗?还是其他什么东西?
我该如何修复这个问题?
cell.contentView = customView
?如果是的话,你应该考虑添加视图而不是替换它:[cell.contentView addSubview:customView]
。 - blldNSTableCellView *newView; newView = [tableView makeViewWithIdentifier:@"PostCell" owner:self];
。 - Colliot