Draw a custom NSTableRowView depending on if next row is group row

☆樱花仙子☆ 提交于 2019-12-06 02:30:03

问题


I have a custom NSTableRowView implementation to display my data cells. The table also contains group rows using a simple NSTextField.

In my custom row view I need to change the drawing of the bottom separator slightly depending on if the next row below is a data cell (i.e. my custom row) or a group header.

In the case of a group header I don't have to draw the separator, otherwise I'll end up with a 2px separator like shown in the screenshot.

Is there a way to get a reference to the next (or previous) NSTableRowView instance from [NSTableRowView drawBackgroundInRect:...]?


回答1:


Am I correct that your table view delegate implements -tableView:rowViewForRow:?

If so, let the table view delegate help:

  1. Add a property drawsSeparator to your custom row class.
  2. In your row class, check the value of this property in drawRect and adjust your drawing accordingly.
  3. Set drawsSeparator on your row in rowViewForRow. You can invoke -tableView:isGroupRow: with row + 1 to determine whether the next row is a group (after checking to make sure you're not on the last row).


来源:https://stackoverflow.com/questions/9324732/draw-a-custom-nstablerowview-depending-on-if-next-row-is-group-row

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!