首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OSX:多个细胞系的NSTableView细胞?

OSX:多个细胞系的NSTableView细胞?
EN

Stack Overflow用户
提问于 2013-09-05 22:03:20
回答 1查看 2.3K关注 0票数 0

拥有多行NSTableView单元的最佳方法是什么?比如说5还是6?

我知道这个问题和"iOS: UITableView cells with multiple lines?“的答案,但是OSX的机制似乎不同。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-06 07:37:14

基于这个答案,View-based NSTableView with rows that have dynamic heights

在您的NSTableView的委托中:

代码语言:javascript
复制
@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 ;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18646697

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档