Get height of content in NSTableView

一笑奈何 提交于 2020-01-01 05:22:33

问题


Is there a way to get the height of the content in an NSTableView. In iOS, you can use the -contentSize method of UIScrollView. However, the -contentSize method of NSScrollView seems to just return the height of only the visible section of the NSScrollView, not including whatever is offscreen.

So, how can this be done on a Mac?


回答1:


- (NSSize)contentSize in Appkit returns the size of the NSClipView, and not the height of the content that scrolls inside the table view. I don't know how UIScrollViews work, but on OS X, an NSScrollView has a "content view" (more aptly named the NSClipView) that clips the actual content, which is provided by a document view (scrollable if it has a size larger than that of the clip view) that is a subview of the clip view.

As a side note, the NSScrollView scrolls by setting the document view's bounds origin (to the best of my knowledge).

It looks like what you want is the height of the document view, the height of the actual content. For that, try something like

scrollView.documentView.frame.size.height 



回答2:


You can get the real content height of NSTableView by

  • Objective-C version: tableView.intrinsicContentSize.height

  • Swift version: tableView.intrinsicContentSize.height



来源:https://stackoverflow.com/questions/11322139/get-height-of-content-in-nstableview

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