Search code examples
macosxcode5nstableview

How to change NSTableView Height programmatically


I'm developing an app for MacOSX in Xcode 5.

I have a NSTableView which I'm filling with data programmatically

I want to know how to change programmatically TableView height depending of the number of rows that contains, I tried something but doesn't work, this is my code:

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

[_tableView setFrame: frame];

but I still having on screen the same tableView's height, how to adapt it?


Solution

  • I think what you want to resize is the parent NSScrollView's size, because it contains your NSTableView so make a IBOutlet pointing to your NSTableView's NSScrollView like this

    @property (weak) IBOutlet NSScrollView *scrollview;
    

    and then you may apply your formula

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