Need help debugging (adding imgViews to a view)
Hi,
I'm trying to create several small ImageViews to a View (imgView is the View containing the ImageViews).
However, it's not working properly. 95% of the times I get the following debug:
[INFO] 1
[INFO] 2
[INFO] 3
[INFO] 1
[INFO] 2
[INFO] 3
[INFO] 1
[INFO] 2
[INFO] 3
[INFO] 1
[INFO] 2
[INFO] 3
[INFO] 1
The function running is:
function pushSlideArray(arr){
arr.forEach(function(e){
var url = (typeof(e) == 'object') ? e.m : '';
var miniSlide = Ti.UI.createImageView({
image:url,
top:(50*row+196),
left:(62*col-52),
width:52,
height:40,
backgroundColor:'#fff',
borderWidth:1,
borderColor:'#aaa',
borderRadius:3
});
if (url.length > 0 && typeof(miniSlide) == 'object'){
Ti.API.info('1');
imgView.add(miniSlide);
Ti.API.info('2');
row = (col == slidesPerRow) ? row + 1 : row;
col = (col == slidesPerRow) ? 1 : col + 1;
miniSlide.addEventListener('click', function(){
mainSlide.image = e.l;
});
Ti.API.info('3');
}
});
}
So it suddenly stops as 1 - just before adding an ImageView to imgView. The amount of (1,2,3)-loops is random.
arr
is an array of objects e
, while
object e
contains l
(large img url) and m
(medium img url).
Anyone?
2 Answers
-
var imgView = Ti.UI.createView({ top:50, left:0, width:320, height:'auto' });
The URL's are correct, that's not the problem.
-
url = (typeof(e) == 'object') ? e.m : '';
this creates an imageview with null for "image" in certain conditions(typeof(e) != 'object').
Put the minislide constructor inside the if loop. Should fix the issue and save some cpu, as you create the image if you are adding it or not to the imgView.