NSTableView Row Height based on NSStrings

前端 未结 5 1746
失恋的感觉
失恋的感觉 2020-12-15 13:48

Basically, I have an NSTableView with 1 collumn, and I\'m inserting long strings into each row. However, not all the strings are long, so I\'d like the height of each row to

5条回答
  •  庸人自扰
    2020-12-15 14:35

    Create an NSTextFieldCell instance and match its font/size/etc. to that of your column's data cell. Ask it for the -cellSizeForBounds:, passing in a rect of the desired width for the column, with a large height (FLT_MAX?). The result should be an NSSize whose height you can use.

    It gets trickier if you have more than one multi-line text column because you'll need to consider all the cells in that row, taking the largest as your row height. If you expect a lot of rows on average, you'll probably want to cache this work, updating it as necessary, then simply referencing it when the row height delegate method is called.

提交回复
热议问题