问题
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.
回答1:
Check NoodleStickyRowTableView:
http://www.noodlesoft.com/blog/2009/09/25/sticky-section-headers-in-nstableview/
It's part of NoodleKit:
https://github.com/MrNoodle/NoodleKit
回答2:
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
回答3:
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. 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.
It is only available on View Based tableviews.
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
来源:https://stackoverflow.com/questions/5369186/uitableview-like-nstableview