问题描述
我正在尝试为字典中的每个元素添加一个子视图(来自 NSViewController
的视图)到 NSScrollView
以获得一种表视图,但有很多比单元格更灵活.
I'm trying to add one subview (view from an NSViewController
) for every element in a dictionary to a NSScrollView
to get kind of a tableview, but with much more flexibility over the cells.
是否可以(以编程方式)放置例如100 个子视图相互下方,所以你必须向下滚动 NSScrollView
才能到达最后一个元素?
Is it possible to place (programmatically) e.g. 100 subviews underneath each other so that you have to scroll down the NSScrollView
to get to the last element?
推荐答案
简短的回答是肯定的.我以前做过这个,我向你保证它会起作用.让我也向你保证,它并不像看起来那么简单 ;)
The short answer is yes. I have done this before, and I assure you that it will work. Let me also assure you that it is not quite as simple as it looks ;)
这样做的方法是维护一个内容视图,在其中您以编程方式将所有自定义行添加为子视图.请注意,您要么必须在添加所有行之前 调整 contentView 的大小,要么必须关闭行视图的自动调整大小.将你的 scrollView
的 documentView
设置为这个自定义的 contentView,你应该很高兴.
The way to do this is to maintain one content view, in which you add all of your custom rows as subviews programmatically. Note that you will either have to resize the contentView before adding all of the rows, or you will have to turn off autoresizing for the row views. Set the documentView
of your scrollView
to this custom contentView, and you should be good to go.
这篇关于向 NSScrollView 添加大量视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!