【发布时间】:2015-10-26 14:15:58
【问题描述】:
当我使用自定义视图作为基于视图的 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 有效。
上面好像有什么东西。但它是界面生成器中显示的“表格列”吗?还是别的什么?
我该如何解决这个问题?
【问题讨论】:
-
如何初始化 UITableViewCell?
cell.contentView = customView?如果是,您应该考虑添加视图而不是[cell.contentView addSubview:customView] -
@AurélienBouilland,在界面构建器中拖动一个自定义视图,就在表格列的正下方(作为它的子项),将类设置为我的视图类,然后
NSTableCellView *newView; newView = [tableView makeViewWithIdentifier:@"PostCell" owner:self];; -
@AurélienBouilland,其他详情请参考Custom view created with Interface Builder does not render when called in other views。
-
您介意放一些您点击的代码或屏幕截图吗?
-
@SruitA.Suk,请查看我的更新。
标签: objective-c cocoa