macos - 操作系统: NSTableView cells with multiple lines?

标签 macos cocoa nstableview

NSTableView 单元格具有多行的最佳方式是什么?比如说 5 个或 6 个?

我知道这个问题和答案“iOS: UITableView cells with multiple lines? ”,但该机制在 OSX 上似乎有所不同。

最佳答案

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

在您的 NSTableView 的委托(delegate)中:

@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 ;
}

关于macos - 操作系统: NSTableView cells with multiple lines?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18646697/

相关文章:

swift - 如何将自定义样式应用于 NSTableHeaderView?

java - Java 7 和 Java 8 可以在 OSX 上共存吗

macos - 如何从系统剪贴板粘贴到控制台 Vim?

objective-c - 从另一个类访问 NSWindow

objective-c - 如何使用 Objective C 将应用程序分配给 Mac OS X Lion 的所有桌面(空间)?

objective-c - NSTableView 的绑定(bind)值,但工具提示也被设置

cocoa - 嵌入 NSScrollView 的自定义 View 中 NSTableView 的滚动问题

macos - osx dns上的docker beta用于容器之间的链接不可用

python - PyQt5 不会为 Python 3 安装

ios - 这是 NSIndexSet enumerateIndexesUsingBlock 中的错误吗?