NSTableView Row Height based on NSStrings

前端 未结 5 1745
失恋的感觉
失恋的感觉 2020-12-15 13:48

Basically, I have an NSTableView with 1 collumn, and I\'m inserting long strings into each row. However, not all the strings are long, so I\'d like the height of each row to

5条回答
  •  孤城傲影
    2020-12-15 14:32

    Code as per the above answer ...

        NSString *string = [[_tableViewDataSourceArray objectAtIndex:rowIndex] 
                                  valueForKey:@"StringToDisplay"];
    
        NSTableColumn *tableColoumn = [aTableView
                                  tableColumnWithIdentifier:@"TableColumnIdentifier"];
    
        if (tableColoumn) 
        {
         NSCell *dataCell = [tableColoumn dataCell];
         [dataCell setWraps:YES];
         [dataCell setStringValue:string];
         NSRect myRect = NSMakeRect(0, 0, [tableColoumn width], CGFLOAT_MAX);
         heightOfRow =  [dataCell cellSizeForBounds:myRect].height;
        }
    

提交回复
热议问题