View based NSTableView with each view contains 3 labels with should resize based on Text

依然范特西╮ 提交于 2019-12-10 23:36:45

问题


I need to create a view based tableview in Popover as specified below:

  • Tableview should be placed in Popover(Popover height should be same as tableview).
  • Each row should contain a view.
  • Each row view will contain 3 labels.
  • Labels should be auto re sizable based on its text height.
  • Based on 3 labels height, Cell row height should resize.
  • Based on all cell rows, tableview height should resize.
  • Based on tableview height, Popover should resize.

I have done this in a static format, but i need to do it in more dynamic format(in future i should be able to add more rows using same classes and methods).

Main problem i am facing is, i am unable calculate the size of cell view in tableView:heigthOfRow: since i don't know the text of labels in this point of time. So i just created tableview cells in loadView itself and saved in array, and fetching from array in tableview delegate methods. But i think this is wrong way of doing so.

Note: All data to tableview will be given while loading the view itself. Labels are not editable.


回答1:


Cocoa system resizes the subviews based on superview ,I think scenario that you are looking for is to resize super view based on subview size. Following 2 solutions i can suggest right awyay,

1.You can choose to post notification upon size change in each subview and make immediate superview observe that.

2.Use globals for size of each subview in your case 3 labels, and have an API to calculate finalRect in your view of view based table view.

Hope this helps:) have a nice day.



来源:https://stackoverflow.com/questions/17323239/view-based-nstableview-with-each-view-contains-3-labels-with-should-resize-based

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