How can I have the only column of my NSTableView take all the width of the TableView?

别来无恙 提交于 2020-08-20 23:08:12

问题


I am currently trying to learn a bit of Cocoa (using the book Cocoa Programming for Mac OS X). In one of the exercises, we set up a NSTableView with only one column, to act as a list of things.

What annoys me is that in Interface Builder, I could not find a way to have the (only) column always take the full width of the NSTableView. As a consequence, it always somehow looks like there are 2 columns when there is actually only one.

Any idea ?


回答1:


This is just an IB problem that happens all the time (I'm not sure why). To solve this, simply just resize the table view to the size smaller than the 2nd column, then drag it back to the size you want and the 2nd column will disappear.




回答2:


Here's how I did it in Xcode 4.6...

In IB, select the table view and go to the Attributes Inspector. Choose 'Uniform' for 'Column Sizing'. Then, select the table column and choose 'Autoresizes with Table' for 'Resizing'.

These options correspond to:

[tableView setColumnAutoresizingStyle:NSTableViewUniformColumnAutoresizingStyle];
[tableColumn setResizingMask:NSTableColumnAutoresizingMask];



回答3:


I had to use both steps - sam's answer + the comment by David Douglas.

[tableView  setColumnAutoresizingStyle:NSTableViewUniformColumnAutoresizingStyle];
[tableColumn setResizingMask:NSTableColumnAutoresizingMask];

 //AND 
 [tableView sizeLastColumnToFit];


来源:https://stackoverflow.com/questions/7545490/how-can-i-have-the-only-column-of-my-nstableview-take-all-the-width-of-the-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!