0

我是 Titanium 的新手,在尝试将其用于 Android 时遇到了 2 个看似简单的问题。

1)我试图通过单击按钮导航到下一页。但相反,它向我显示了一个空白的黑屏。我知道我的第二页CreateNewMeetup.js是正确的,因为我尝试将其显示为我的应用程序的登录页面并且它有效。我的代码如下: -

应用程序窗口.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

不确定您的第二个问题是什么,请检查您的设备日志和崩溃报告,否则无法知道发生了什么。

于 2013-02-19T04:26:43.770 回答
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

方法二

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 回答