Pages

2011-07-23

ビュー・ベースのNSTableViewをさわってみたよ

Lionでましたね。世のCocoa系男子の皆さんはAPI Diffを見て興奮したり、新APIのGuideを眺めたり、各所をclass-dumpして廻ったりしていると思います。

さて、Lionではついに念願のビュー・ベース・テーブルビューがサポートされました。要するに、今までテーブルの中身はセルじゃないといけなかったのが、ビューを突っ込めるようになったということです。これで「プログレスバーがテーブルビューに入らない!」なんて騒ぐ必要がなくなりますね。NSCollectionView使えば同じようなことできるけど、そんなの知りません。

というわけで、ビューベースのテーブルを作ってみましょう。

Xcode 4.1内のInterface Builderでxibを開き、適当なウインドウにテーブルビューを追加します。そして、インスペクタの中にContent Modeっていう項目があるので、View Basedを選択します。

すると、NSTableColumnの直下にNSTableCellViewなんていうセルだかビューだかどっちなんだよって感じの名前のビューが追加されます。このビューがセルの代わりにテーブルコンテンツの表示を担います。

このNSTableCellViewをInterface Builderで適当にデザインしてあげましょう。ここでは画像とテキストを一つずつ表示するビューにしました。

次に、テーブルビューのコンテンツを保持するNSArrayControllerを追加し、これに対してバインディングを設定します。

まず、NSTableViewのcontentをNSArrayControllerのarrangedObjectsにバインドします。注意したいのは、従来のセルベースのテーブルではNSTableViewではなくNSTableColumnをNSArrayControllerにバインドしてたんだけど、ビューベースではNSTableViewにバインドしなければならないという点です。忘れがち。

次に、ビュー上のアイテムをバインドする必要があるわけですが、バインド先はNSTableCellViewにします。

あとは、NSArrayControllerに適当なコンテンツを設定するよよう実装してビルドして実装すれば、ビューベーステーブルの出来上がり。


ここで使ったプロジェクトをGitHubにおいておきます:ViewBasedTableSample

2 件のコメント:

  1. It is solely based on luck hence even newbie on-line on line casino players can attempt their luck and win. This recreation also has the next return to the player proportion than different on-line on line casino games, as you have have} a high likelihood of successful 36 times your wager amount if the ball falls on your chosen quantity. Gambling homes had been banned in South Korea till 1967 when games of probability had been permitted in massive 토토사이트 motels for vacationers.

    返信削除
  2. You can be taught more about the standards we follow in producing accurate, unbiased content material in oureditorial policy. Further complicating the equation is Disney's indirect possession stake in DraftKings through its ESPN subsidiary. Perhaps it is unsurprising, then, that Chris Krafcik, Eilers & Krejcik gaming analyst, said the deal would "make no cash" when its news was released. ESPN, the biggest TV sports activities community in the United States, and ESPN+ could mint income from content material, bet365 advertising, and sportsbooks tied to their brands.

    返信削除