简体   繁体   中英

Resize Table Column when NSWindow resizes

I am working on a Cocoa application in which I am using NSTableView.

Now I want the widths of the columns in the table view to be auto-resized when the user resizes or maximizes the window, by either dragging the application from a corner, or by clicking the zoom button.

Any help will be appreciated.

Make sure your table view itself resizes when the window resizes, by setting up constraints or setting its autoresizing mask.

Then set the table's overall column autoresizing style. In a storyboard or XIB, you do this by selecting the table view (not the scroll view that contains it) and then setting the “Column Sizing” popup in the Attributes inspector. In code, you set the table view's columnAutoresizingStyle . The different styles are described under NSTableViewColumnAutoresizingStyle . If you want all of the columns to expand or contract during a resize, set it to NSTableViewUniformColumnAutoresizingStyle .

Then set up each column's autoresizing behavior if necessary.

If you are setting up your table in a XIB or storyboard, you can select the column and then set its resizing behavior under the Attributes inspector.

If you are creating a column in code, set the resizingMask of each NSTableColumn to include whichever resizing mode bits you want. The default is to allow both user resizing and autoresizing, so you shouldn't need to do anything.

如果摆弄列调整大小掩码或tableView调整大小设置没有任何作用,请确保最后一列实际上触及了表格视图的右侧,即使看起来确实如此。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM