NSTableView添加按钮或任何其他自定义对象

时间:2018-05-02 08:54:21

标签: objective-c macos cocoa nstableview

我试图以编程方式将Button添加到NSTableView,这也是以编程方式定义的,到目前为止还没有运气。我的最新代码是:

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
        auto dataRow = _tasks[row];
    if([tableColumn.identifier isEqualToString:@"Id"]) {
        NSTextField* text = [[NSTextField alloc] init];
        text.stringValue = [NSString stringWithUTF8String:dataRow[0].c_str()];
        return text;

    } else if([tableColumn.identifier isEqualToString:@"Name"]) {
        NSTextField* text = [[NSTextField alloc] init];
        text.stringValue = [NSString stringWithUTF8String:dataRow[1].c_str()];
        return text;

    } else if([tableColumn.identifier isEqualToString:@"Check"]) {
        NSTableCellView* cellView = [[NSTableCellView alloc] initWithFrame:NSMakeRect(0, 0, 200, 100)];



        NSPopUpButtonCell* popupButtonCell = [[NSPopUpButtonCell alloc] init];
        [popupButtonCell setPullsDown:YES];
        [popupButtonCell insertItemWithTitle:@"dsadsa1" atIndex:0];
        [popupButtonCell insertItemWithTitle:@"dsadsa2" atIndex:1];

        NSPopUpButton* popupButton = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(0, 0, 200, 100) pullsDown:YES];

        popupButton.cell = popupButtonCell;

        [popupButton insertItemWithTitle:@"dsadsa" atIndex:0];
        [popupButton insertItemWithTitle:@"dsadsa" atIndex:1];

        NSTextField* text = [[NSTextField alloc] init];
        NSTextFieldCell* textCell = [[NSTextFieldCell alloc] initTextCell:@"dsadsad"];
        text.stringValue = [NSString stringWithUTF8String:"titleee"];
        text.cell = textCell;

        [cellView addSubview:text];
        [cellView addSubview:popupButton];

        return cellView;

    }

由于某种原因,最后一列显示为空

0 个答案:

没有答案