UITableView-like NSTableView

2019-03-28 03:09发布

I wondered how I can make a NSTableView to behave like a UITableView on iOS. For example, splitting the content into sections as well as the typical behaviour of the section headers.

Is that possible? If so, how?

Thank you very much.

3条回答
混吃等死
2楼-- · 2019-03-28 03:34

One of the differences is that UITableView's "cells" are actually Views, while NSTableView's are proper cells. Views suck up more memory and there's a bit of work involved in getting NSTableView to accept views like cells, then a bit more to optimize it so that if you have a huge list it isn't too memory intesnive.

Luckily it's already (mostly) been done, and there's a github project:

1) https://github.com/Perspx/PXListView#readme (also check his blog for more info) 2) http://blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview/

Good luck

查看更多
We Are One
3楼-- · 2019-03-28 03:39

I wasted several days on this - so you don't have to.

There is a Twitter UI framework TwUI which they went to a lot of trouble to get their desktop clients to look and behave like the iPhone. The Appkit is showing its age these days.

The con with this library is you can't add NSViews to their TWUIViews. This maybe fine if you haven't spent a lot of time creating custom nsviews. You can try this fork which I hacked to mimic the sticky header view. It has group based tableviews like uitableview. enter image description here https://github.com/johndpope/osx-stickyheaders

It turns out Apple have a nice sample library here https://developer.apple.com/library/mac/samplecode/TableViewPlayground/Introduction/Intro.html

And a simplified version here which demonstrates the FloatsGroupRows property with this line

[self.tableView setFloatsGroupRows:YES] 

which for all intents and purposes makes the nstableview / sections look like a uitableview. https://github.com/TomLiu/PlayTableView

The con with that is - it's not available for cell based table views.

enter image description here

It is only available on View Based tableviews.

enter image description here

Since Microsoft have recently reversed engineered UIKit including the UITableView - in c++, it may one day someone be so kind to port this back to OSX. An exercise for the reader. https://github.com/Microsoft/WinObjC/blob/master/Frameworks/UIKit/UITableView.mm

查看更多
登录 后发表回答