如何以编程方式更改TableView高度

时间:2014-07-10 23:03:16

标签: macos xcode5 nstableview

我正在为XCode5中的MacOSX开发应用程序

我有一个NSTableView,我正在以编程方式填充数据

我想知道如何以编程方式更改TableView高度,具体取决于包含的行数,我尝试了一些但不起作用,这是我的代码

    NSRect frame = _tableView.frame;
    frame.size.height = [myDataArray count]*22;

    [_tableView setFrame: frame];

但我仍然在屏幕上有相同的tableView的高度,如何适应它?

提前感谢支持

1 个答案:

答案 0 :(得分:4)

我认为您要调整大小的是父NSScrollView的大小,因为它包含您的NSTableView 所以让IBOutlet像这样指向你的NSTableView的NSScrollView

@property (weak) IBOutlet NSScrollView *scrollview;

然后你可以申请你的公式

NSRect frame = _scrollview.frame;
frame.size.height = [myDataArray count]*22;

[_scrollview setFrame: frame];
相关问题