开发者

NSCollectionView with different heights: How to do this on desktop?

Thanks to this post I now know how to make a table with different row heights on iPhone. (With UITableView)

How to do this on a Mac?

Should I use NSTableView? How a开发者_开发知识库bout NSCollectionView? I feel like NSTableView is too complicated - at least much more complicated than UITableView. I mean, I don't need all the headers and stuff.


Here's an example. Imagine a todo list. Some todos can be pretty long and won't fit in one row. What would you do on iPhone, iPad and Mac?


NSTableView is the equivalent object to UITableView, though it is a bit more complicated. If you don't need headers you don't have to display them, anyhow.


Should I use NSTableView?

Yes.

How about NSCollectionView?

Yes.

It depends on what you're doing. If you're displaying a one-dimensional collection of objects, especially in a form similar to the Finder's icon view, then you want NSCollectionView. If you're displaying a table where each column displays an aspect of each row (e.g.: rows = people; columns = name, title, department, etc.), then you want NSTableView.

In an NSCollectionView, you can set the minimum and maximum item size as a property of the view, and you can set the size of each item as a property of the item.

In an NSTableView, you can set the height of a row by being the table view's delegate and responding to tableView:heightOfRow:. If you want to return the usual row height, ask the table view for its rowHeight and return that; if you want to return an unusual height, do so.

Personally, I find NSTableView easier to work with. You can set it up most if not all of the way in IB; about the only time you need to write any code is for custom drawing, double-click actions, or, yes, variable row heights.

For your to-do list example, I would use an NSTableView, with a checkbox button cell in one column for the “done” property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜