带有文本环绕单元格的 NSOutlineView:heigthOfRow

发布于 2024-10-25 07:48:24 字数 656 浏览 4 评论 0原文

我正在尝试使用多行单元格实现 NSOutlineView

根据此站点和其他站点的建议,我在视图的委托中提出了以下代码。

- (CGFloat)outlineView:(NSOutlineView *)outlineView heightOfRowByItem:(id)item {
    NSTableColumn *column = [outlineView outlineTableColumn];
    NSCell *cell = [column dataCell];

    [cell setStringValue:[item valueForKey:@"label"]];

    return [cell cellSizeForBounds:NSMakeRect(0.0, 0.0, [column width], CGFLOAT_MAX)].height;
}

大纲表列中的单元格设置为换行。

然而,我得到了一种奇怪的图形行为 - 文本行重叠,如 http://screencast.com/t 中所示/ewJUwRmlGZqh。看起来细胞的大小合适,但没有压低下面的细胞。

有人可以帮助我吗?

I'm trying to implement an NSOutlineView with multiple-line cells.

Following advice from this and other sites, I have come up with the following code in the view's delegate.

- (CGFloat)outlineView:(NSOutlineView *)outlineView heightOfRowByItem:(id)item {
    NSTableColumn *column = [outlineView outlineTableColumn];
    NSCell *cell = [column dataCell];

    [cell setStringValue:[item valueForKey:@"label"]];

    return [cell cellSizeForBounds:NSMakeRect(0.0, 0.0, [column width], CGFLOAT_MAX)].height;
}

The cell in the outline table column is set to wrap.

I get, however, a strange graphical behavior—the text lines overlap, as seen in http://screencast.com/t/ewJUwRmlGZqh. It seems like the cell is getting the right size, but not pushing down the underlying cells.

Could someone help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼睛会笑 2024-11-01 07:48:24

在我的脑海中,我很确定这个委托方法仅在重新加载表格单元格的数据时被调用,而不是在其他事件(例如边界更改)期间被调用。

当需要调整行高时,您需要调用重新加载,这将导致表为每个可见单元格调用此方法,从而执行调整大小。

Off the top of my head, I'm pretty sure this delegate method is only called when reloading the table cell's data, not during other events like a bounds change.

You'll need to invoke a reload when it's time to adjust row heights, which will cause the table to call this method for each of the visible cells, and consequently perform the resize.

扛起拖把扫天下 2024-11-01 07:48:24

(这是作为建议编辑发布的,但应该是它自己的答案。我不知道这是否有意义。@asavartsov:请随意将此答案重新发布为您自己的答案,并给我留下评论,以便我删除此副本。)

该代表每当打电话时都会打电话 。有人询问 item 的行高。这种情况尤其发生在由边界更改引起的绘图操作中。但是,正如文档中所述,

NSTableView 可能会缓存此方法返回的值,因此如果您想更改行高,请确保通过调用 noteHeightOfRowsWithIndexesChanged: 使行高无效。 NSTableView 自动使 reloadDatanoteNumberOfRowsChanged 中的整个行高缓存失效。

当需要调整行高时,您需要调用 noteHeightOfRowsWithIndexesChanged:reload,这将导致表格为每个可见单元格调用此方法,并且因此执行调整大小。

(This was posted as a suggested edit, but should have been an answer of its own. I don't know if it makes sense or not. @asavartsov: feel free to repost this answer as your own, and leave me a comment so I'll delete this copy.)

This delegate called whenever someone asked for row height at item. This happen, particularly, in drawing operations which con-sequenced by bounds changing. But, as stated in the documentation,

NSTableView may cache the values this method returns, so if you would like to change a row's height make sure to invalidate the row height by calling noteHeightOfRowsWithIndexesChanged:. NSTableView automatically invalidates its entire row height cache in reloadData and noteNumberOfRowsChanged.

You'll need to invoke a noteHeightOfRowsWithIndexesChanged: or reload when it's time to adjust row heights, which will cause the table to call this method for each of the visible cells, and consequently perform the resize.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文