【问题标题】:Titanium error: Uncaught TypeError: Cannot call method 'add' of undefinedTitanium 错误:未捕获的 TypeError:无法调用未定义的方法“添加”
【发布时间】:2013-12-06 09:38:28
【问题描述】:

我有一个错误,并且仅在 android 上: 我有这样的代码:

var selfWin;

var blackScreen;
var actInd;

var Login = require('ui/common/Login');
var myLogin;

var HomeView = require('ui/common/Home');
var homeView;

function ApplicationWindow() {

    var selfWin = Ti.UI.createWindow({
        backgroundColor:'#ffffff',
        navBarHidden:true,
        exitOnClose:true
    });

    blackScreen = Ti.UI.createLabel({
        backgroundColor:'#000000',
        opacity:0.40,
        top:0,
        height:'100%',
        width:'100%',
        zIndex:100
    });
    actInd = Ti.UI.createActivityIndicator({
        width:50,
        height:50,
        zIndex:101
    });

    selfWin.add(blackScreen);
    selfWin.add(actInd);
    Ti.App.HideBlackScreen();

    Ti.App.GoToFirstView();

    return selfWin;
}

Ti.App.ShowBlackScreen = function ShowBlackScreen() {
    blackScreen.show();
    actInd.show();
};
Ti.App.HideBlackScreen = function HideBlackScreen() {
    blackScreen.hide();
    actInd.hide();
};

Ti.App.GoToFirstView = function GoToFirstView() {
    myLogin = new Login();
    selfWin.add(myLogin);
    if (homeView) {
        selfWin.remove(homeView);
    }
};

Ti.App.GoToHome = function GoToHome() {
    homeView = new HomeView();
    selfWin.add(homeView);
    selfWin.remove(myLogin);
};

//make constructor function the public component interface
module.exports = ApplicationWindow;

这个错误发生在 selfWin.add(myLogin);在 GoToFirstView() 函数中,并且仅在 android 上。 有人可以帮助我吗? 非常感谢

【问题讨论】:

    标签: android function titanium undefined


    【解决方案1】:

    尝试使您的 selfWin 对象像下面这样全局化。因为它是私有变量,在应用程序函数()之外不存在。有两种方法可以实现。

    1.

       var selfWin;
        function ApplicationWindow() {
               selfWin = Ti.UI.createWindow({
                backgroundColor : '#ffffff',
                navBarHidden : true,
                exitOnClose : true
            });
        }
    

    2. 使用您的函数传递您的窗口对象,如下所示。

    Ti.App.GoToFirstView(selfWin);
    Ti.App.GoToFirstView = function GoToFirstView(selfWin) {
    myLogin = new Login();
    selfWin.add(myLogin);
    if (homeView) {
        selfWin.remove(homeView);
    }
    };
    

    最好的问候, 尼丁查夫达

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-23
      • 2012-08-27
      • 1970-01-01
      • 2013-01-27
      • 1970-01-01
      • 2013-08-31
      相关资源
      最近更新 更多