2014年5月29日木曜日

NSTableView, NSCell-based or NSView-based

NSTableView がどんな場合に cell-based か view-based で作成されるべきかわからなかったのでメモ。

NSCell-Based Tables Are Still Supported
In OS X v10.6 and earlier, each table view cell was required to be a subclass of NSCell. This approach caused limitations when designing complex custom cells, often requiring you to write your own NSCell subclasses. Providing animation, such as progress views, was also extremely difficult. In this document these types of table views are referred to as NSCell-based table views. NSCell-based tables continue to be supported in OS X v10.7 and later, but they’re typically used only to support legacy code. In general, you should use NSView-based tables.

Although you use the same Interface Builder techniques to create both NSView-based and NSCell-based table views (and to add columns to a table), the code required to provide individual cells, populate the table view, and support programmatic editing differs depending on the table type. In addition, you use different Cocoa bindings techniques depending on whether you’re working with an NSView-based or NSCell-based table.
- Table View Programming Guide for Mac -

Mac OS X 10.6 とその以前のバージョンでは、各テーブルセルは NSCell のサブクラスである必要がありました。複雑なカスタムセルを設計する際に、独自の NSCell のサブクラスを記述しなければならないことがあり、このアプローチは限界をもたらしました。プログレスビュー(進捗状況を表示するビュー)のようなアニメーションを提供するときはまた、非常に困難でした。本ドキュメントではこのタイプのテーブルビューは セルベース(NSCell-based)のテーブルビューと呼びます。セルベースのテーブルは継続して、Mac OS X 10.7 とそれ以降でサポートされますが、典型的には従来のコードをサポートするためだけに使用われます。通常はビューベース(NSView-based)のテーブルを使用するべきです。

ビューベースとセルベースのテーブルビュー両方を作成(そしてテーブルにカラムを追加)するためにインターフェイスビルダーで同じ手法を用いますが、個々のセルを提供するために必要とされるコード、テーブルビューへのデータの格納、そしてプログラム的な編集のサポートは、テーブルのタイプに応じて異なります。加えて、ビューベースまたはセルベースのテーブルで作業しているかどうかに応じて、異った Cocoa バインディングの手法を用います。

Most Tables Are Based on NSView
Most tables are NSView based, which means that each cell is provided by an NSView subclass, often by NSTableCellView (or a subclass). Some tables are NSCell based, which means that each table cell is based on a subclass of NSCell. For the most part, NSCell-based tables are used to support legacy code; if you’re creating a new app, you want to use NSView-based tables. In this document, a table is assumed to be NSView based unless specified otherwise.
- Table View Programming Guide for Mac -

ほとんどのテーブルは NSView に基づいています。それは、それぞれのセルが NSView や、しばしば NSTableCellView(またはサブクラス)によって提供されることを意味します。いくつかのテーブルは NSCell に基づいていて、それぞれのテーブルセルが NSCell のサブクラスに基づいていることを意味します。ほとんどの場合、セルベースのテーブルは従来のコードをサポートするために使用されます。新たにアプリケーションを作成するならば、ビューベースのテーブルを使っていただきたい。本ドキュメントでは特に断りがない限り NSView に基づいたテーブルを仮定しています。

というわけで、レガシーコードをサポートするとき以外はビューベースで。



さらにテーブルのバインディングについてメモ。 同ドキュメントには "Populating a Table View Using Cocoa Bindings" でビューベースのテーブルのバインディングについての説明がある。以下まとめ。
  1. ArrayController に Content Array を設定する。(モデルオブジェクトの入った Array)
  2. テーブルビューの Content に ArrayController, arrangedObjects でバインドする
  3. TableCellView のサブビューにそれぞれ Table Cell View, objectValue.{property} でバインドする。

以上。セルベースのテーブルはカラムにバインドするとかなんとか。詳しくは "Creating Bindings for an NSCell-Based Table View" で。関係ないけど "populate"という単語はプログラム関係の翻訳では、データベースにデータを入れるという意味で使用される。移入する、とか格納するとか、投入するとか。

0 件のコメント:

コメントを投稿