【问题标题】:custom NSTableViewCell自定义 NSTableViewCell
【发布时间】:2012-07-20 22:25:58
【问题描述】:

我自定义 NSTableView 就像我在 UITableView 中所做的一样。我实现了数据源和委托。在代码中,我是这样做的:


- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
    ZJCellView *cellView = [tableView makeViewWithIdentifier:cellIdentifier owner:self];
    //this is a custom view
    if (cellView == nil)
    {
        CGRect rect = CGRectMake(0, 0, tableView.frame.size.width, kTableViewCellHeight);
        cellView = [[[ZJCellView alloc] initWithFrame:NSRectFromCGRect(rect)] autorelease];
        cellView.identifier = cellIdentifier;


      // some other controls

    }
    return cellView;

我像在 iOS 中一样进行自定义。 问题是左右边框都有一条线,例如:

我尝试更改单元格视图的框架,但似乎没有用。 由于这是在 iOS 中自定义单元格的正确方法,我想知道在 Cocoa 中哪里错了。

任何人都可以帮助我吗? 谢谢。

【问题讨论】:

    标签: cocoa nstableview nstableviewcell


    【解决方案1】:

    最后,我发现是Cell Space,可以在笔尖设置。

    【讨论】:

      【解决方案2】:

      在 iOS 中:

      Tableviewcells 与 Tableview 相同。它们是自动调整大小的。如果您在 cellForRowAtIndexPath: 方法中为单元格设置框架,则不会更改任何内容。

      对于宽度,您需要更改表格视图的宽度。 对于高度,您需要实现 tableview 的委托方法 heightForRowAtIndexPath: 或设置 rowHeight 属性。

      但是我不知道NSTableView怎么样,我觉得差不多吧。

      【讨论】:

      • 我已经用表格视图的宽度初始化了单元格视图。问题存在。
      猜你喜欢
      • 2016-12-09
      • 1970-01-01
      • 1970-01-01
      • 2012-07-08
      • 2011-02-22
      • 1970-01-01
      • 2013-02-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多