0

NSTableView拥有多行细胞的最佳方法是什么?比方说 5 还是 6 ?

我知道这个问题和答案“ iOS:具有多行的 UITableView 单元格? ”但机制似乎在OSX.

4

1 回答 1

1

基于这个答案基于视图的 NSTableView 具有动态高度的行

在您的代表中NSTableView

@interface MenuDelegate ()

@property (nonatomic, weak) NSArrayController * theArrayController ;

@property (nonatomic, strong) NSTextFieldCell * anExtraTextFieldCell ;
@property (nonatomic) NSRect tallRect ;

@end



@implementation  MenuDelegate



#pragma mark - Initialisations


- (id)initwithArrayController:(NSArrayController *)theArrayController;
{
    self = [super init] ;

    if (self)
    {
        self.theArrayController = theArrayController ;

        self.anExtraTextFieldCell = [[NSTextFieldCell alloc] init] ;
    }

    return self ;
}



- (CGFloat)     tableView:(NSTableView *)tableView
              heightOfRow:(NSInteger)row {

    if (!self.tallRect.size.width)
    {
        NSTableColumn * firstColum = tableView.tableColumns[0] ;
        self.tallRect = NSMakeRect(0, 0, firstColum.width, CGFLOAT_MAX);
    }

    // Access the content of the cell.
    NSString * content = [self.theArrayController.arrangedObjects[row] valueForKey:@"title"] ;
    self.anExtraTextFieldCell.stringValue = content ;

    CGFloat result = [self.anExtraTextFieldCell cellSizeForBounds:self.tallRect].height + 5;


    if (result < [tableView rowHeight])
    {
        result = [tableView rowHeight] ;
    }

    return result ;
}
于 2013-09-06T07:37:14.820 回答