Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize NSTableView or NSScrollView depending on number of rows in table

I have a view-based NSTableView which is embedded in an NSScrollView. It has custom cells that are x number of pixels high. The NSScrollView is the same size as the panel that it is a subview of. I want to resize the entire NSTableView depending on how many rows are in the table.

Everything is working except the resizing. Resizing the scroll view manually in IB seems to have the desired affect, but NSSrollView does not seem to have a class method to resize its view (like NSView has setFrame). Should I be resizing the scollview, the tableview, both, or something else? Does NSScrollView have a setFrame method or similar that I am missing?

Thanks.

like image 477
rick Avatar asked May 01 '12 06:05

rick


2 Answers

Before you try to do it programmatically, make sure you have the outline view's autosizing masks set up properly in the nib file. It sounds like you simply want the outline view (and its scroll view) to always remain the same size as the window that it's inside.

By default, the autosizing masks of an NSScrollView/NSOutlineView combo that you place into a window looks like the following:

enter image description here

In other words, it's set up to always remain the same size as it is now, no matter how large you resize the window to be.

What you want to do is to change the autosizing masks to look like in the image below:

enter image description here

To do that, you click in the white autosizing box wherever there's a dotted red line to toggle it into a solid red line. Once it's configured that way, the scroll view (and table view) will always (automatically) be resized to be the same size as the window that it's in.

There may also be a way to achieve this using Lion's new "auto layout" feature, but I'll have to leave that to someone who has more experience with it.

like image 157
NSGod Avatar answered Oct 18 '22 14:10

NSGod


In case you really need to do this (such as when you want all rows to fit in the scrollview alleviating the need to scroll) and the scroll view is only a portion of the window/view you can do:

[[myTableView enclosingScrollView] setFrame:newFrameRect];
like image 45
dbainbridge Avatar answered Oct 18 '22 13:10

dbainbridge