0
我想創建一個非常簡單的NSTableCellView與文本框和按鈕。我的代碼佈局NSTableCellView如下。我希望textfield的寬度爲100px。NSTableCellView內NSTextField的寬度
- (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佔據了整個行:
我在做什麼錯?