【问题标题】:UI freeze when creating a new window on a button click在单击按钮时创建新窗口时 UI 冻结
【发布时间】:2012-12-18 10:13:26
【问题描述】:

我是 Titanium 的新手,我遇到了一个问题。 在我的 app.js 中,我包含一个左侧菜单和窗口控件(app.js 和 leftmenu.js)

我想在用户点击菜单项时加载一个窗口。基本上,我想在用户选择主页按钮时加载 app.js 主窗口。 为此,我在 leftmenu.js 文件中加入了以下代码:

var newWin = Titanium.UI.createWindow({
    url: "app.js",
    zIndex: 0
});
win.close(); // closing main window
leftMenu.close(); // closing left menu
newWin.open(); //should reload the main window and the leftmenu

它重新加载窗口,但所有控件都被禁用。我们不能点击任何控件。就像所有控件都在一个不可见的层下一样。 有什么想法吗?

我复制/粘贴代码部分,也许会更清楚:)

btnaccueil.addEventListener('click',function(e) {
   var newWin = Titanium.UI.createWindow({        
       url: "app.js",
       zIndex: 0
   });

   // Closing current instance for freeing memory
   win.close();
   leftMenu.close();
   newWin.open({animated:true});
   Ti.API.info(var_dump(newWin));
});

【问题讨论】:

    标签: titanium appcelerator


    【解决方案1】:

    您好,一个月后我知道了,但是您使用的是 require 和 exports/module.exports 吗?这是一个关于如何以正确方式使用按钮事件打开新窗口的示例,我认为不推荐使用 url 属性,所以我希望这个示例可以帮助您理解

    employee.js

    //Current window (employee window)
    var employeeWin = Ti.UI.currentWindow;
    
    //define button
    var moveToDetailBtn = Ti.UI.createButton({
       width      : 200,      //define the width of button
       height      : 50,      //define height of the button
       title         : 'Show Detail'   //Define the text on button
    });
    
    //Click event to open the Employee Details window
    moveToDetailBtn.addEventListener('click', function(){
    
       //Call a export function
       var win = require('employeeDetails').getEmployeeDetailSWin;
    
       //Create new instance
       var employeeDetailsWin = new win();
    
       //Open the Employee Details window
       employeeDetailsWin.open();
    });
    
    //Add the button to the window
    employeeWin.add(moveToDetailBtn);
    

    在employeeDetails.js中

    exports.getEmployeeDetailSWin = function(){
    
       //Creates a new window
       var empDetailsWin = Ti.UI.createWindow({
          backgroundColor   : '#ffffff'      //Define the backgroundcolor of the window
       });
    
       //Addin a label to the window
       empDetailsWin.add(Ti.UI.createLabel({
          width      : 100,      //Define width of the label
          height      : 50,      //Define height of the label
          title         : 'Employee Details'
       }));
    
       return empDetailsWin;
    };
    

    除了我不确定你是否可以导出你的 app.js 尝试使用新的 .js

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-29
      • 2018-11-19
      相关资源
      最近更新 更多