Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

info : Dynamic scrollview add views on 1.4

This bugged me for a whole night since the release of 1.4, hope my finding would benefit some of you with dynamic add views to scrollview object.

I have a custom gallery with "swipe-like-scrollable" image viewer and scrollview thumbnails. The images are dynamic so i have a load more thumbs to append more images to the scrollviews to prevent overhead.

In the past, at least with 1.3.x, i can just add new views though a loop without errors. With 1.4, it will hang, the program would froze while looping. The workaround is storing this views in an array of views objects first then add the array to the scrollview later.

Keep in mind that this only happen on adding new views to existing scrollview, not when u first creating it.

Not longer working.

for loop {
var view = createView...
scrollview.add(view)
}

Working with 1.4

for loop {
var view = createView...
 viewarray[i]=view
}
scrollview.add(viewarray)

[update]
Spoke too soon, adding more views to scrollview froze running on device after a couple loop, and you can't even load the app after that. No error, no nothing, just choke. Rolling back to 1.3.3 and it's running ok on device. Looks like a very serious memory issue adding more views to scrollview, dynamically, on 1.4.

— asked July 28th 2010 by Daniel Lim
  • 1.4
  • dynamic
  • ipad
  • scrollview
  • tip
  • views
1 Comment
  • I'm having the same problem with nearly the exact same code. The thing that's killing me right now is it only fails 1 out of 3 times, so I might think I've fixed it and then it pops back up. I'll try your array fix and see what happens…

    — commented August 3rd 2010 by Jason Harris

8 Answers

  • Spoke too soon, adding more views to scrollview froze running on device after a couple loop, and you can't even load the app after that. No error, no nothing, just choke. Rolling back to 1.3.3 and it's running ok on device. Looks like a very serious memory issue adding more views to scrollview, dynamically, on 1.4.

    — answered July 28th 2010 by Daniel Lim
    permalink
    0 Comments
  • I am having the exact same problem, I am adding multiple imageViews to a scrollView in a loop. This worked fine on 1.3 and now just hangs on 1.4.

    — answered July 29th 2010 by Glen Yates
    permalink
    0 Comments
  • Try adding the scrollview to the window first and then add the views to it. That worked for me to workaround the issue.

    — answered August 6th 2010 by Rob Marscher
    permalink
    1 Comment
    • We are taking about dynamically add "new" rows to a scrollview that's already on a window, and it failed after few loops on device (not emulator), which was working fine on 1.3.x

      — commented August 6th 2010 by Daniel Lim
  • An update to dynamic add views to scrollview bugs on 1.4

    I decided not to pursue the adding new views, the problem is when it failed, the app froze, and user can't even reopen the app on next try. A crash would be just fine :)

    Anyway, Instead adding more views. I code the hard way, transform it into a paging gallery. The image gallery is paginated into 20 thumbnails each loop, next or pre page would replace current set thumnails. That seems to work ok.

    — answered August 6th 2010 by Daniel Lim
    permalink
    2 Comments
    • "…the app froze, and user can't even reopen the app on next try…"

      That's because the app is frozen (apps don't start from scratch on iOS 4, they pick back up where you left off). You'll have to double-tap the home button, then press and hold your app icon until the red minus signs appear, then touch the red minus sign for your app to actually quit it.

      — commented August 18th 2010 by Glen Yates
    • Glen, i know iOS4 background feature. The app is configured not to run in background

      <key>UIApplicationExitsOnSuspend</key>
      <true/>
      

      Thanks

      — commented August 23rd 2010 by Daniel Lim
  • Having exact the same problem on device only. It hangs in the loop and even reboots my device! (iPod Touch 3G).

    It was working perfectly before the iOS4 update. A lot of my users are having problems now.

    — answered August 18th 2010 by Richard Venneman
    permalink
    0 Comments
  • Has anyone found a work around or solution to this issue? I opened a ticket, but have not received a response yet.

    — answered August 23rd 2010 by Jason Harris
    permalink
    1 Comment
    • Tried a continuous build today but the problem doesn't appear to be solved yet.
      :(

      — commented August 24th 2010 by Richard Venneman
  • This now is an official bug at Lighthouse. Looks like it will be fixed in 1.5..

    https://appcelerator.lighthouseapp.com/projects/32238-titanium-mobile/tickets/1643-scrollview-more-than-10-children-views-cause-app-freeze

    — answered August 26th 2010 by Richard Venneman
    permalink
    0 Comments
  • I think I have a work around for this issue and maybe this will help some of you. I'm doing something similar where I dynamically add new views to my scroll view based on new updates from a website, sort of like adding new content to a rolling rss feed reader. What I did is this:

    App.loadTimedEventList = function (newSampleArrayList) {
            // Get the location of the last element in the scroll view to start adding new elements
        var top = this.sampleScrollViewItems.length  * 110;    /* 110 is the height of the view in the list */
    
           // Delete any elements that were left (if any) from the last addition
        this.newScrollViewItems = [];
    
            // loop through and add the new items to array (each item is a Ti.UI.View element)
        for (var i = 0; i < newSampleArrayList.length; ++i){
            var item = App.createViewItem(0,  (i * 110) + top );
            this.newscrollItems.push(item);
        }
    
           // now we loop and create a timer to execute adding the elements to the scrollview 1 second apart
        for (var k =0; k < eventList.length; k++) {
            setTimeout(function () {
                sampleScrollView.fireEvent('addItem');
            }, (k + 1) * 1000);
        }
    };
    
    // .....  Some lines on UP (this code here would be defined up higher in the file)
    
    var sampleScrollView = Ti.UI.createScrollView({...});
    
    // This code will execute on the timer 1sec apart
    sampleScrollView.addEventListener('addItem', function(e) {
            // get the item out of this list
        var item = App.newScrollViewItems.pop();
    
            // add it to the control
        this.sampleScrollViewItems.push(item);
          sampleScrollView.add(item);
    });
    
     //
    

    Hope this helps anyone!

    — answered October 28th 2010 by Donelle Sanders Jr
    permalink
    1 Comment
    • Wow this looks like an awesome promising code.

      Though I can't seem to get this working. Can you show an example of it working in a app or explain a little more on getting this to work

      thanks and good job

      — commented October 29th 2010 by Patrick van Zadel
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.