我正在尝试使用文本字段和按钮创建一个非常简单的 NSTableCellView。我的 NSTableCellView 布局代码如下。我希望文本字段的宽度为 100 像素。
- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
MyTableCellView *cellView = [outlineView makeViewWithIdentifier:@"MyTableCellView" owner:self];
if (cellView == nil) {
cellView = [[MyTableCellView alloc] initWithFrame:NSMakeRect(0, 0, NSWidth(outlineView.bounds), [outlineView rowHeight])];
NSTextField *textField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, [outlineView rowHeight])];
[cellView addSubview:textField];
cellView.textField = textField;
NSButton *button = [[NSButton alloc] initWithFrame:NSMakeRect(108, 0, 50, [outlineView rowHeight])];
[cellView addSubview:button];
cellView.button = button;
cellView.identifier = @"MyTableCellView";
}
cellView.textField.stringValue = item.stringValue;
return cellView;
}
但是,当我这样做时, NSTextField 占据了整行:
我究竟做错了什么?