带有文本环绕单元格的 NSOutlineView:heigthOfRow
我正在尝试使用多行单元格实现 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我的脑海中,我很确定这个委托方法仅在重新加载表格单元格的数据时被调用,而不是在其他事件(例如边界更改)期间被调用。
当需要调整行高时,您需要调用重新加载,这将导致表为每个可见单元格调用此方法,从而执行调整大小。
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.
(这是作为建议编辑发布的,但应该是它自己的答案。我不知道这是否有意义。@asavartsov:请随意将此答案重新发布为您自己的答案,并给我留下评论,以便我删除此副本。)
该代表每当打电话时都会打电话 。有人询问 item 的行高。这种情况尤其发生在由边界更改引起的绘图操作中。但是,正如文档中所述,
当需要调整行高时,您需要调用
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,
You'll need to invoke a
noteHeightOfRowsWithIndexesChanged:
orreload
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.