ウィンドウの中身はNSViewというオブジェクトにオブジェクトを配置しそれを表示する、という形になる。ビューオブジェクトはウィンドウオブジェクトに対して動的に追加・削除が可能。
ツールバーのGeneric、Advancedに対応するビューをそれぞれ作成する。MainMenu.xibにてCustom Viewを探しObjectリストにまずは配置。二つ配置する。


Custom Viewにそれぞれ名前を付けておく。編集時にわかり易いようにね。Custom Viewオブジェクトを選択した状態でIdentity Inspectorを開く。下の方にあるLabelで名前を入力できる。それぞれCustom View - GeneralとCustom View - Advancedとする。


Generalに対応するビューにラベルとテキストフィールドオブジェクトを配置。大きさや配置はウィンドウをビュー側に合わせる形を取るので適当に。ここでホームページとなるURLを入力する。ラベルはダブルクリックで編集出来るので、Home Page:と入力した。Custom View - Advancedは取りあえず放置。

前回のswitchView_()ハンドラでこのビューをツールバーのアイコンに合わせて設定ウィンドウ内で表示する。
まずどのツールバーアイコンが押されたのか判断するとこから。どのアイコンが押されたかの判断はswitchView_()ハンドラの引数senderで判断が可能。senderはどのアイコンがクリックされたのかの情報を持っている。その情報はツールバーアイテムのAttribute Inspectorで設定されたTagの値。Tagの値はデフォルトで-1が設定されている。これを任意で設定。早速設定。Generalは10、Advancedは20とした。


判断するコードを書く。こんな感じ。
on switchView_(sender) set tagNumber to tag of sender as real if tagNumber is 10 then log "General clicked." else if tagNumber is 20 then log "Advanced clicked." end if end switchView_
*tag of senderは明示的にreal型として扱う
これでアプリケーションを実行。設定ウィンドウのツールバーアイコンクリックでログ出力が確認出来る。

今回はこれで終わり。具体的にCustom Viewの表示が出来るのは多分次回。
0 件のコメント:
コメントを投稿