2010年1月4日月曜日

Cocoa Binding 2

Cocoa Binding 2

Controllerによってバインド方法が微妙に異なるので、以下メモ。

<ControllerからModelへのバインディング>
NSObjectControllerからModelオブジェクト
1.NSObjectController選択→Connectionsインスペクタ
2.contentアウトレットからModelオブジェクトを接続
(Modelオブジェクト内に対応する変数を配置)
※モデルオブジェクトが単一なので(接続先が自明なので)Bindingsインスペクタの代わりにアウトレットを使うと考えられる。

NSArrayControllerからModelオブジェクト
1.NSArrayController選択→Bindingsインスペクタ
2.Content Arrayタブ→Bind toにチェック→Modelオブジェクトを選択
3.Controller Key→空欄(選択不可)
4.Model Key Path→Modelオブジェクト内のNSArray/NSMutableArray型の変数名
※モデルオブジェクトを複数想定しているため、Bindingインスペクタを使う。
※Controller自身なので、Controller Keyの指定は必要ない。

<Viewのvalue値をController(+Model)へバインディング>
NSControl(スライダーなど)からNSObjectController
1.NSControl選択→Bindingsインスペクタ
2.Valueタブ→Bind toにチェック→Object Controllerを選択
3.Controller Key→selection
4.Model Key Path→Modelオブジェクト内のNSArray/NSMutableArray型の変数名
※selectionはNSObjectControllerで指定されたモデルオブジェクトを指す。
※Model Key Pathへの設定はselectionで指定されているモデルオブジェクトの変数名を指す。

NSControl(スライダーなど)からNSArrayController
1.NSControl選択→Bindingsインスペクタ
2.Valueタブ→Bind toにチェック→Array Controllerを選択
3.Controller Key→arrangedObjectなど
4.Model Key Path→空欄

以上

0 件のコメント: