固定高度NSTableView,避免滚动 [英] Fixed Height NSTableView, Avoid Scrolling

查看:629
本文介绍了固定高度NSTableView,避免滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 NSTableView ,具有非常小的固定行数。

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

code> NSTableView 在Interface Builder中, NSTableView 包含在 NSScrollView 。我没有找到一种方法使表存在于滚动视图的上下文之外。因为表只有少量的行,我不想要它滚动。我想要表的大小基于行数,我想要底部边框紧挨着最后一行的底部。

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.

如果我取消选中Interface Builder中的显示垂直滚动条复选框,滚动条不会出现,但是当我选择最后一行时,表格向下滚动一个像素。

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?

谢谢。

推荐答案

awakeFromNib 中,可以写入(未测试):

In awakeFromNib you could write something like (untested):

NSScrollView *scrollView = [tableView superview];
NSView *container = [scrollView superview];
[[tableView retain] autorelease];
[tableView removeFromSuperview];
[scrollView removeFromSuperview];
[container addSubview:tableView];
[container setFrameSize:[tableView frame].size];

或者,在Interface Builder中,您可以通过更改为列表视图模式从滚动视图中提取表视图(主菜单 - >视图 - >列表)。然后展开视图层次结构,直到看到表视图。您可以将其拖出滚动视图,但不能拖动到另一个视图中。

Alternatively, in Interface Builder you can extract a table view from a scroll view by changing to list view mode (Main Menu -> View -> as List). Then expand the view hierarchy until you see the table view. You can drag that out of the scroll view, but not into another view. You can just hook this up to an outlet and add it to a view programmatically.

当行数改变时,你仍然需要更新容器的高度。 。

You'll still need to update the height of the container when the number of rows change.

这篇关于固定高度NSTableView,避免滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆