基于视图的NSTableView与每个视图包含3个标签,应该基于文本调整大小 [英] View based NSTableView with each view contains 3 labels with should resize based on Text

查看:155
本文介绍了基于视图的NSTableView与每个视图包含3个标签,应该基于文本调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Popover中创建一个基于视图的tableview,如下所示:




  • Tableview应该放在Popover

  • 每个行视图将包含3个标签。

  • 根据文字高度自动调整标签大小。

  • 基于3个标签高度,单元格行高度应调整大小。




在所有单元格行中,表格高度应调整大小。
  • 根据表格高度,Popover应调整大小。

    我以静态格式,但我需要做更多的动态格式(在未来我应该能够添加更多的行使用相同的类和方法)。



    我遇到的主要问题是,我无法计算 tableView中的单元格视图大小:heigthOfRow:我不知道在这个时间点的标签的文本。
    所以我刚刚在loadView本身创建了tableview单元格并保存在数组中,并从tableview委托方法中的数组中获取。但我认为这是错误的方式这样做。



    注意:加载视图本身时将给出tableview的所有数据。标签不可编辑。

    解决方案

    Cocoa系统根据superview调整子视图的大小,我认为您正在寻找的方案是调整大小基于子视图大小的超级视图。
    以下2个解决方案我可以建议正确的awyay,



    1.你可以选择在每个子视图的大小更改后发布通知,并立即监督观察。 / p>

    2.使用全局变量作为每个子视图的大小,共有3个标签,并且有一个API用于在基于视图的表视图中计算finalRect。



    希望这有助于:)有一个美好的一天。


    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.

    解决方案

    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.

    这篇关于基于视图的NSTableView与每个视图包含3个标签,应该基于文本调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆