Titanium Mobile:无法在页面之间导航 [英] Titanium Mobile: cant navigate between pages

查看:19
本文介绍了Titanium Mobile:无法在页面之间导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i am new to Titanium and i am have 2 seemingly simple problems while trying to use it for the Android.

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

1) i am trying to navigate to the next page on click of a button. but instead it is showing me a blank black screen. i know my second page CreateNewMeetup.js is correct because i tried displaying it as the landing page of my app and it works. my codes are as follows:-

ApplicationWindow.js

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;

创建NewMeetupWindow.js

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 秒),然后它会自行关闭.我猜是应用程序崩溃?但它在模拟器上运行良好.

2) after installing the app onto my device, i tried to launch it. the app shows momentarily (about 3 seconds maybe) and then it shuts down by itself. i guess its an app crash? but it works well on the emulator.

钛金属专家请帮忙:$

推荐答案

您可以在程序中使用以下方法在窗口间导航

You can use the following methods in your program to navigate between windows

方法一

//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;

您可以使用上述任何一种方法.不要混合使用这些方法.

You can use any single method from above. Do not mix the methods together.

您可以使用以下链接作为参考

You can use the following link for references

  1. http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.Window-property-url
  2. http://docs.appcelerator.com/titanium/latest/#!/api/Global-method-require

这篇关于Titanium Mobile:无法在页面之间导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆