Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
699 views
in Technique[技术] by (71.8m points)

cocoa - Fixed Height NSTableView, Avoid Scrolling

I have an NSTableView that has a very small fixed number of rows.

When I create an NSTableView in Interface Builder, the NSTableView is contained within an NSScrollView. I have not found a way to make the table exist outside the context of a scroll view. Since the table only has a small number of rows, I don't want it to scroll. I want the table to resize based on the number of rows, and I want the bottom border immediately under the bottom of the last row.

If I set the height of the scroll view as follows, I get a vertical scroll bar:

height = (numRows * (rowHeight + intercellSpacingHeight))

If I add one pixel to that height, I don't get the scroll bar but I get an extra pixel between the bottom of the last row and the bottom border.

If I uncheck the "Show Vertical Scroller" checkbox in Interface Builder, the scroll bar does not appear but the table scrolls down one pixel when I select the last row.

Is there a way to have the table not scroll at all, and have the bottom border immediately under the last row?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could always extract the NSTableView from its enclosing scrollview (in code or in IB) ... You can embed the table into any container you wish, but it's up to you to maintain the table's size inside the container (and/or grow/shrink the container in response, depending n what you want to do).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...