Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 612
Jesus Avatar asked Dec 06 '25 03:12

Jesus


1 Answers

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];
like image 163
Jesús Ayala Avatar answered Dec 07 '25 20:12

Jesús Ayala



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!