0

私はTitaniumを初めて使用しますが、Androidで使用しようとすると、一見単純な2つの問題が発生します。

1)ボタンをクリックして次のページに移動しようとしています。代わりに、空白の黒い画面が表示されます。CreateNewMeetup.js2番目のページをアプリのランディングページとして表示しようとしたところ、機能するので、2番目のページが正しいことがわかりました。私のコードは次のとおりです:-

ApplicationWindow.js

...

var button = Ti.UI.createButton({
    height:44,
    width:'auto',
    title:'Create New Meetup',
    top:20
});
self.add(button);

button.addEventListener('click', function() {
    var newWindow = Ti.UI.createWindow({
        url : "/ui/common/CreateNewMeetupWindow.js",
        fullscreen: false
    });
    newWindow.open();
});

return self;

CreateNewMeetupWindow.js

//CreateNewMeetUpView Component Constructor
function CreateNewMeetupWindow() {
var self = Ti.UI.createWindow({
    layout : 'vertical',
    backgroundColor:'white'
});

var contactsField = Ti.UI.createTextField({
    borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
    color : '#336699',
    width : 400,
    height : 60
});
self.add(contactsField);

var locationField = Ti.UI.createTextField({
    borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
    color : '#336699',
    width : 400,
    height : 60
});
self.add(locationField);

var lblNotifyMe = Ti.UI.createLabel({
    color : 'black',
    text : 'Notify me when s/he is',
    textAlign : Ti.UI.TEXT_ALIGNMENT_LEFT,
    width : 'auto',
    height : 'auto'
});
self.add(lblNotifyMe);

var btnGo = Ti.UI.createButton({
    title : 'Go',
    height : 'auto',
    width : 100
});

btnGo.addEventListener('click', function() {
    // Check console
    Ti.API.info('User clicked the button ');

});
self.add(btnGo);

return self;
};

2)アプリをデバイスにインストールした後、起動しようとしました。アプリは一時的に表示され(おそらく約3秒)、その後自動的にシャットダウンします。私はそれがアプリのクラッシュだと思いますか?しかし、それはエミュレーターでうまく機能します。

チタンの専門家が助けてください:$

4

2 に答える 2

1

最初の問題についてはurl、CommonJS オブジェクトでプロパティを使用しています。代わりに、次のようにウィンドウをインスタンス化します。

var newWindow = require("/ui/common/CreateNewMeetupWindow");
newWindow.open();

CommonJS モジュールでないurl場合は、このプロパティを使用します。CreateNewMeetupWindow.js

2 番目の問題が何であるかわからない場合は、デバイスのログとクラッシュ レポートを確認してください。そうしないと、何が起こっているのかを知る方法がありません。

于 2013-02-19T04:26:43.770 に答える
1

プログラムで次のメソッドを使用して、ウィンドウ間を移動できます

方法 1

//Your app.js file
var button = Ti.UI.createButton({
    height:44,
    width:'auto',
    title:'Create New Meetup',
    top:20
});
self.add(button);

button.addEventListener('click', function() {
    //By doing this you're opening a new window
    var newWindow = Ti.UI.createWindow({
        url : "ui/common/CreateNewMeetupWindow.js",//Provide the correct path here
        fullscreen: false
    });
    newWindow.open();
});


//Your CreateNewMeetupWindow.js file

var newWindow = Ti.UI.currentWindow;

var contactsField = Ti.UI.createTextField({
    borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
    color : '#336699',
    width : 400,
    height : 60
});
newWindow.add(contactsField);

//You can add other controls here just like I added the contactsField

方法 2

var button = Ti.UI.createButton({
    height:44,
    width:'auto',
    title:'Create New Meetup',
    top:20
});
self.add(button);

button.addEventListener('click', function() {
    var window = require('/ui/common/CreateNewMeetupWindow');
var newWindow = new window();
    newWindow.open();
});

//Your CreateNewMeetupWindow.js file

function CreateNewMeetupWindow() {
    var self = Ti.UI.createWindow({
        layout : 'vertical',
        backgroundColor:'white'
    });

    var contactsField = Ti.UI.createTextField({
        borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
        color : '#336699',
        width : 400,
        height : 60
    });
    self.add(contactsField);

    //Add other controls here

    return self;
}
module.exports = CreateNewMeetupWindow;

上記のいずれかの方法を使用できます。メソッドを混在させないでください。

次のリンクを参考にしてください。

  1. http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.Window-property-url
  2. http://docs.appcelerator.com/titanium/latest/#!/api/Global-method-require
于 2013-02-19T04:32:04.420 に答える