appcelerator titan 中的错误:嵌套的推送动画可能会导致导航栏损坏

发布于 2024-12-12 03:10:34 字数 2997 浏览 0 评论 0原文

我在日志中收到以下消息和一个有问题的导航组 2011-10-27 21:41:21.575 bugtitanium[15903:207] 嵌套推送动画可能会导致导航栏损坏 2011-10-27 21:41:21.945 bugtitanium[15903:207] 在意外状态下完成导航转换。导航栏子视图树可能会损坏。 2011-10-27 21:41:21.946 bugtitanium[15903:207] 在意外状态下完成导航转换。导航栏子视图树可能会损坏。 附上重现代码;第一次加载时,一切正常,点击1次重新加载,单击一行,然后单击后退按钮 做同样的事情并重新加载 2 次,你将不得不按后退按钮 2 次,依此类推...... 有人可以为我提供解决方法或修复吗? 我需要作为异步进程加载和填充表,

代码是

Titanium.UI.setBackgroundColor('#000');
var tabGroup = Titanium.UI.createTabGroup();
var win1 = Titanium.UI.createWindow({  
title:'Tab 1',
backgroundColor:'#fff'
});

var mytasks_helping_button = Ti.UI.createButton({
            title : 'Reload',
            top:0,
            color:'black',
            width:200,
            height:30,
            style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
});
win1.add(mytasks_helping_button);

var mytasks_helping_tableview = Titanium.UI.createTableView({
top:100
});
win1.add(mytasks_helping_tableview);

var tab1 = Titanium.UI.createTab({  
icon:'KS_nav_views.png',
title:'Tab 1',
window:win1
});

function populateData(datasourcetmp,tabletmp){ 
var data = [];
for( i = 0; i < datasourcetmp.length; i++) {
            var row = Titanium.UI.createTableViewRow({
                height : 120,
                backgroundColor:'#fff',
                borderWidth : 0,
                borderColor : 'transparent'
            });

            var my_tasks_table_top_label = Titanium.UI.createLabel({
                text : 'test row:'+i+' date:'+new Date(),
                width : "100%",
                font : {
                    fontSize : 12,
                    fontFamily : 'Helvetica'
                },
                color : "black",
                top : 30,
                height : 20,
                left : 5
            });
            row.add(my_tasks_table_top_label);

            data.push(row);
};

mytasks_helping_tableview.addEventListener('click', function(e) {

            //view a task screen
            var viewTask = Titanium.UI.createWindow({
                height : "100%",
                width : "100%",
                title : "Helping with",
                barColor : 'lightGray'
            });

            var viewTask_top_label = Titanium.UI.createLabel({
                text : 'nested view '+ e.index,
                width : "80%",
                font : {
                    fontSize : 15,
                    fontFamily : 'Helvetica'
                },
                color : "gray",
                top : 10,
                height : 20,
                left : 60
            });
            viewTask.add(viewTask_top_label);


            tab1.open(viewTask);
        });

tabletmp.setData(data);
}
var datasource = ['1','2','3','4','5','6','7'];
populateData(datasource,mytasks_helping_tableview);

mytasks_helping_button.addEventListener('click', function(e) {

populateData(datasource,mytasks_helping_tableview);

});

tabGroup.addTab(tab1);  

tabGroup.open();

I am getting the following message in the logs and a buggy navigation group
2011-10-27 21:41:21.575 bugtitanium[15903:207] nested push animation can result in corrupted navigation bar
2011-10-27 21:41:21.945 bugtitanium[15903:207] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
2011-10-27 21:41:21.946 bugtitanium[15903:207] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
Attaching the code to reproduce ; on the first load, everything is ok, hit 1 time reload , click on one row and click the back button
Do the same and reload 2 times, you will have to hit the back button 2 times, and so on ....
Can someone provide me with a workaround or a fix please ?
I need to load and populate the table as async processes

the code is

Titanium.UI.setBackgroundColor('#000');
var tabGroup = Titanium.UI.createTabGroup();
var win1 = Titanium.UI.createWindow({  
title:'Tab 1',
backgroundColor:'#fff'
});

var mytasks_helping_button = Ti.UI.createButton({
            title : 'Reload',
            top:0,
            color:'black',
            width:200,
            height:30,
            style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
});
win1.add(mytasks_helping_button);

var mytasks_helping_tableview = Titanium.UI.createTableView({
top:100
});
win1.add(mytasks_helping_tableview);

var tab1 = Titanium.UI.createTab({  
icon:'KS_nav_views.png',
title:'Tab 1',
window:win1
});

function populateData(datasourcetmp,tabletmp){ 
var data = [];
for( i = 0; i < datasourcetmp.length; i++) {
            var row = Titanium.UI.createTableViewRow({
                height : 120,
                backgroundColor:'#fff',
                borderWidth : 0,
                borderColor : 'transparent'
            });

            var my_tasks_table_top_label = Titanium.UI.createLabel({
                text : 'test row:'+i+' date:'+new Date(),
                width : "100%",
                font : {
                    fontSize : 12,
                    fontFamily : 'Helvetica'
                },
                color : "black",
                top : 30,
                height : 20,
                left : 5
            });
            row.add(my_tasks_table_top_label);

            data.push(row);
};

mytasks_helping_tableview.addEventListener('click', function(e) {

            //view a task screen
            var viewTask = Titanium.UI.createWindow({
                height : "100%",
                width : "100%",
                title : "Helping with",
                barColor : 'lightGray'
            });

            var viewTask_top_label = Titanium.UI.createLabel({
                text : 'nested view '+ e.index,
                width : "80%",
                font : {
                    fontSize : 15,
                    fontFamily : 'Helvetica'
                },
                color : "gray",
                top : 10,
                height : 20,
                left : 60
            });
            viewTask.add(viewTask_top_label);


            tab1.open(viewTask);
        });

tabletmp.setData(data);
}
var datasource = ['1','2','3','4','5','6','7'];
populateData(datasource,mytasks_helping_tableview);

mytasks_helping_button.addEventListener('click', function(e) {

populateData(datasource,mytasks_helping_tableview);

});

tabGroup.addTab(tab1);  

tabGroup.open();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

喜你已久 2024-12-19 03:10:34

在上面的代码中,您每次调用 populateData 时都会添加一个事件侦听器。

mytasks_helping_tableview.addEventListener('click', function....

添加事件侦听器不会“替换”现有的事件侦听器,因此它会在第一次“加载”并打开多个窗口后多次触发。

只需将 mytasks_helping_tableview.addEventListener 调用移至 populateData 函数外部即可。

In the code above, you are adding an event listener every time you call populateData.

mytasks_helping_tableview.addEventListener('click', function....

Adding a event listener does NOT 'replace' the existing event listener so it is firing multiple time after the first 'load' and opening multiple windows.

Just move the mytasks_helping_tableview.addEventListener call to outside the populateData function.

找个人就嫁了吧 2024-12-19 03:10:34

实际上,一种更灵活的修复方法是创建表实例的映射,然后每次删除以前的实例并重建,从而使代码能够被不同的表组合使用

    Titanium.UI.setBackgroundColor('#000');
    var tabGroup = Titanium.UI.createTabGroup();

    var win1 = Titanium.UI.createWindow({  
      title:'Tab 1',
      backgroundColor:'#fff'
    });


     var mytasks_helping_button = Ti.UI.createButton({
            title : 'Reload',
            top:0,
            color:'black',
            width:200,
            height:30,
            style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
     });
     win1.add(mytasks_helping_button);


    var tab1 = Titanium.UI.createTab({  
       icon:'KS_nav_views.png',
       title:'Tab 1',
       window:win1
    });

    var tableView={};

   function populateData(datasourcetmp,tableName){ 

  if(tableView[tableName]){
    win1.remove(tableView[tableName]);
    delete tableView[tableName];
  }

  var tabletmp = Titanium.UI.createTableView({
    top:100
  });
  win1.add(tabletmp);
  tableView[tableName] = tabletmp;

  var data = [];
  for( i = 0; i < datasourcetmp.length; i++) {
            var row = Titanium.UI.createTableViewRow({
                height : 120,
                backgroundColor:'#fff',
                borderWidth : 0,
                borderColor : 'transparent'
            });

            var my_tasks_table_top_label = Titanium.UI.createLabel({
                text : 'test row:'+datasourcetmp[i]+' date:'+new Date(),
                width : "100%",
                font : {
                    fontSize : 12,
                    fontFamily : 'Helvetica'
                },
                color : "black",
                top : 30,
                height : 20,
                left : 5
            });
            row.add(my_tasks_table_top_label);

            data.push(row);
};

tabletmp.addEventListener('click', function(e) {
            //view a task screen
            var viewTask = Titanium.UI.createWindow({
                height : "100%",
                width : "100%",
                title : "Helping with",
                barColor : 'lightGray'
            });

            var viewTask_top_label = Titanium.UI.createLabel({
                text : 'nested view '+ e.index,
                width : "80%",
                font : {
                    fontSize : 15,
                    fontFamily : 'Helvetica'
                },
                color : "gray",
                top : 10,
                height : 20,
                left : 60
            });
            viewTask.add(viewTask_top_label);


            tab1.open(viewTask);
        });

      tabletmp.setData(data);
     }



     var datasource = ['1','2','3'];
      populateData(datasource,'mytasks');

     mytasks_helping_button.addEventListener('click', function(e) {
      datasource = ['4','5','6','7'];
     populateData(datasource,'mytasks');
    });

    tabGroup.addTab(tab1);  
    // open tab group
    tabGroup.open();

Actually a more flexible way to fix that enable the code to by used by different table comp is to create a map of table instances and every time delete the previous instance and rebuild

    Titanium.UI.setBackgroundColor('#000');
    var tabGroup = Titanium.UI.createTabGroup();

    var win1 = Titanium.UI.createWindow({  
      title:'Tab 1',
      backgroundColor:'#fff'
    });


     var mytasks_helping_button = Ti.UI.createButton({
            title : 'Reload',
            top:0,
            color:'black',
            width:200,
            height:30,
            style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
     });
     win1.add(mytasks_helping_button);


    var tab1 = Titanium.UI.createTab({  
       icon:'KS_nav_views.png',
       title:'Tab 1',
       window:win1
    });

    var tableView={};

   function populateData(datasourcetmp,tableName){ 

  if(tableView[tableName]){
    win1.remove(tableView[tableName]);
    delete tableView[tableName];
  }

  var tabletmp = Titanium.UI.createTableView({
    top:100
  });
  win1.add(tabletmp);
  tableView[tableName] = tabletmp;

  var data = [];
  for( i = 0; i < datasourcetmp.length; i++) {
            var row = Titanium.UI.createTableViewRow({
                height : 120,
                backgroundColor:'#fff',
                borderWidth : 0,
                borderColor : 'transparent'
            });

            var my_tasks_table_top_label = Titanium.UI.createLabel({
                text : 'test row:'+datasourcetmp[i]+' date:'+new Date(),
                width : "100%",
                font : {
                    fontSize : 12,
                    fontFamily : 'Helvetica'
                },
                color : "black",
                top : 30,
                height : 20,
                left : 5
            });
            row.add(my_tasks_table_top_label);

            data.push(row);
};

tabletmp.addEventListener('click', function(e) {
            //view a task screen
            var viewTask = Titanium.UI.createWindow({
                height : "100%",
                width : "100%",
                title : "Helping with",
                barColor : 'lightGray'
            });

            var viewTask_top_label = Titanium.UI.createLabel({
                text : 'nested view '+ e.index,
                width : "80%",
                font : {
                    fontSize : 15,
                    fontFamily : 'Helvetica'
                },
                color : "gray",
                top : 10,
                height : 20,
                left : 60
            });
            viewTask.add(viewTask_top_label);


            tab1.open(viewTask);
        });

      tabletmp.setData(data);
     }



     var datasource = ['1','2','3'];
      populateData(datasource,'mytasks');

     mytasks_helping_button.addEventListener('click', function(e) {
      datasource = ['4','5','6','7'];
     populateData(datasource,'mytasks');
    });

    tabGroup.addTab(tab1);  
    // open tab group
    tabGroup.open();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文