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.
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.
-
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.
-
Try adding the scrollview to the window first and then add the views to it. That worked for me to workaround the issue.
-
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.
-
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.
-
Has anyone found a work around or solution to this issue? I opened a ticket, but have not received a response yet.
-
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
-
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!