开发者

Custom Record View in Cocoa Application

I want to create a custom view in a Cocoa application. It's basic开发者_开发知识库ally a record view, where the data from multiple database fields is displayed in a long list. Here's a quick mockup:

Custom Record View in Cocoa Application

Now there are several things to consider:

  • The number and type of fields is dynamic
  • Fields may be formatted differently (the short fields are in one line, the long fields are in a separate paragraph. In the future, images might be included as well.)
  • The text is not editable, but it should be selectable so users can copy it

I already have some experience in Cocoa, but I don't know how I should best create this basic layout. In iOS I would probably use a UITableView with custom cells, but NSTableView is very different and probably not suited for this application.

Several ideas come to my mind:

  1. Just use a WebView and create the layout as HTML. I have a lot of experience with HTML, so layouting should be easy. On the other hand, this seems like a dirty hack.
  2. Use an NSAttributedString. Since this layout is mostly text, this should be possible. Then just put that into a read-only NSTextView. It might be hard to get the layout pixel-perfect.
  3. Create a lot of NSTextFields and NSBoxes programmatically. Layouting will be complicated and involve a lot of mathematics (but I like maths, so that's okay)
  4. Make a custom view and do all drawing in drawRect:

What is the best solution? I'm overwhelmed by the amount of choices that are available, and I can't see which solution is cleanest. Does anybody have experience with creating dynamic data views?


WebView is probably the quickest solution for you.
And most important, the user will never notice it.
Only the selecting behavior might be less convenient.

Other solutions (probably 'bettter and cleaner' once implemented correctly):

NSTabeView with custom cells:
http://www.martinkahr.com/2007/05/04/nscell-image-and-text-sample/
http://juliuspaintings.co.uk/cgi-bin/paint_css/animatedPaint/070-NSTableView-ImageAndTextCell.pl

NSScrollView with custom NSViews:
http://juliuspaintings.co.uk/cgi-bin/paint_css/animatedPaint/022-NSCollectionView-random.pl

Once you get some experience with NSTabeView / NSScrollView / NSScrollView,
they are almost easier and quicker to implement then the WebView :)


Use NSTextField or NSTextView and set editable to NO and leave selectable enabled.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜