Titanium Community Questions & Answer Archive

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

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?

— asked August 9th 2010 by Caspar Jespersen
  • debugging
  • imageview
  • iphone
0 Comments

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.

    — answered August 9th 2010 by Caspar Jespersen
    permalink
    0 Comments
  • 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.

    — answered August 9th 2010 by Dan Tamas
    permalink
    2 Comments
    • Hi Tamas. Thanks for your answer.

      The (typeof(e) == 'object') was just a temporary way of trying to fix it. My e is always an object, so this is not causing the problem. I have however corrected my code according to your contributions, as you have a point.

      The problem still occurs, though, and I've come to realize that it's mainly when the length of arr is high. The more images, the higher risk of failing. An array with 56 objects crash almost everytime (it has crashed every time I've tried it).

      Any ideas?

      — commented August 9th 2010 by Caspar Jespersen
    • Update:

      When I delte my build folder, and create another build it works perfectly. It must have something to do with the caching of the images?

      — commented August 9th 2010 by Caspar Jespersen
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.