Return to Snippet

Revision: 46775
at May 24, 2011 22:29 by chlab


Initial Code
/**
 * Replace (update) one view of a ScrollablView with a new one
 *
 * @param   object  The scrollableView
 * @param   object  The old view to be replaced
 * @param   object  The new view to replace the old one
 * @return  void
 */
function replaceView(scrollableView, oldView, newView)
{
  // loop all the views in the scrollable view
  for (var i = 0, newViews = [], l = scrollableView.views.length; i < l; i++)
  {
    // replace the old view with the new one
    if (i == scrollableView.currentPage)
      newViews.push(newView);
    // leave the other views unchanged
    else
      newViews.push(scrollableView.views[i]);
  }

  // update the scrollableView's views array with the new one
  scrollableView.views = newViews;
}

Initial URL
http://www.chlab.ch/blog/archives/mobile-development/replace-update-view-scrollableview-titanium-mobile

Initial Description
It’s pretty straightforward, we loop the existing Views of the ScrollableView and copy each View, replacing the one to be change, to a new array. Then we tell the ScrollableView to use our new Views-array for it’s Views.
I hope this helps someone.

Initial Title
Replace (update) a View in a ScrollableView in Titanium Mobile

Initial Tags
replace, mobile

Initial Language
JavaScript