javascript - Strange behaviour on custom NavBar for Titanium -


first of all, please don't recommend me use native ios/android objects, test custom controls , need work.

i'm encountering strange behavior while using custom navbar in android or ios. seems right until close window directly (by code) in custom navbar. secont time open window navbar, old objects (label, buttons, etc.) still there. post example: first, main window call addform in navbar:

var ui = require('navigation'); var nav = ui.createnavigatorgroup();  alloy.globals.navbar = nav;  nav.open(winaddpill, {animated: true}); 

initial data

when user press add button (you can't see, in bottom of form), autoclose window in nav, after save data, code:

alloy.globals.navbar.close($.win);

if that, when call window, e.g., show info (which has delete button in right), title label mixed previous window:

alloy.globals.navbar.open(winpill, {animated: true}); 

mixed data

as can see, mixed, must shown instead: right image

if continue open new windows, still mixing. avoid behavior? fighting problem 4 days , don't find solution.

finally, custom navbar i'm using:

exports.createnavigatorgroup = function() {      var me = {};          var navviews = []; // stack of navigation bars         var navview;          function pushnavbar() {             navview = ti.ui.createview({                 top: 0,                 height: 44,                 backgroundcolor: '#bbb'             });             navviews.push(navview);         };          function popnavbar() {             navviews.pop();             navview = navviews[navviews.length - 1];         };          // make sure have navview available prepare         pushnavbar();          me.open = function(win) {             navview.add(ti.ui.createlabel({                 text: win.title,                 color: 'black'             }));              navview.win = win;             win.add(navview);              win.navbarhidden = true;             win.open();          // prepare next window             pushnavbar();         };          me.close = function(win) {             if (navviews.length > 1) {                 // close window on nav                 popnavbar();                 win.close();             }         };     return me; }; 

also added simple , runable project in github 3 empty windows testing. can see question here , project here.

i found f***g problem!!!

i analized detail code , found it. problem resides in new navview prepared config new objects, so, lets say, have 2 windows opened, have 3 navviews. number 3 clear, nothing inside, ready setleftbutton before open new window it.

but if close actual window, navview 2 objects, code makes "popnavview" remove last (empty) navview 3 , sets actual navview 2 ready use... with actual objects inside.

the simple solution is... remove after set, simple line inside popnavbar:

function popnavbar() {       navviews.pop();       navview = navviews[navviews.length - 1];       navview.removeallchildren(); }; 

i re-do github code let available others wants use functional custom navbar.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -