0

iOS の右ナビゲーション ボタンを Titanium のウィンドウに追加しようとしています。

コードは、Titanium が提供する元の「マスター/詳細」開始テンプレートであり、MasterView.js で、ナビゲーション バーにボタンを追加しようとします。

しかし、次のように動作しません。

var addBtn = Ti.UI.createButton({
    systemButton:Ti.UI.iPhone.SystemButton.ADD
});
//self.setRightNavButton(addBtn);
var win1 = Titanium.UI.currentWindow;
win1.setRightNavButton(addBtn);

これはエラーで失敗します:

[エラー] : スクリプト エラー = 'undefined' は MasterView.js のオブジェクトではありません ('win1.setRightNavButton' を評価しています) (14 行目)。

このボタンをナビゲーションバーに追加するにはどうすればよいですか? いくつかの例を見てきましたが、それらはすべてナビゲーションバーが適切に宣言されていることに依存しています。この場合、Titanium は各プラットフォームに固有の AplicationWindow.js で navbar を宣言し、navbar ボタンを定義することになっている MasterView.js 関数とファイルを呼び出すため、これは不可能です。

4

2 に答える 2

0

Ti.UI.currentWindow only works if there is a window already open. The error you have is coming from the fact that when you create the MasterView, you have not yet opened up the window.

Look inside ApplicationWindow.js, you will see that you create the masterview before even opening the window.

If you want to set navbar items, either add them in the ApplicationWindow, app.js, or pass the window to the MasterView.

于 2013-04-16T21:36:58.683 に答える
0

Ti.UI.currentWindowパラメーターを使用してウィンドウが開かれた場合にのみ機能しurlます。その場合、urlパラメーターによって参照されるコントローラーには、Ti.UI.currentWindowプロパティがウィンドウに設定されます。

于 2016-05-09T01:35:12.460 に答える