Another ImageView problem after upgrading to 1.5.1

You must Login before you can answer or comment on any questions.

I had a bug introduced into my app with the 1.5.1 release and thought I'd share. I had an image that toggled between two states when clicked. To detect the current state, I previously could read the .image property and compare it to a string like so:

var iview = Ti.UI.createImageView({image:'checked.png'});
if (iview.image == 'checked.png') {Ti.API.info('The image is checked.')};
Running that code now gives:

[ERROR] Script Error = invalid method 'toString:' at app.js (line 2).

Apparently the .image property is no longer a string nor does it have a toString method. Not sure if this is a bug or a feature.

In my case, the work-around is to add another property:

var iview = Ti.UI.createImageView({image:'checked.png', is_checked:true});
if (iview.is_checked) {Ti.API.info('The image is checked.')};
This has been tested on the iPhone simulator only.

2 Answers

I'm having the same problem. But I cannot use your workaround because I need the actual URL for the string. How to read the image in 1.5.1? When I log Ti.API.info(theImageView.image) it logs the value correctly. But when I compare if ("theURL.jpg" == theImageView.image) it throws the same invalid method toString error.

— answered 2 years ago by Sid K
answer permalink
2 Comments
  • just add the actual string as a propery when you set the imageView, then you can compare it later

    — commented 2 years ago by Aaron Saunders

  • @Aaron - Thanks but that's a very roundabout way of doing things. I have code that was working with the previous SDK and it's not working any more. I'd set the URL property but that's deprecated. Ti.API.info logs it just fine so there has to be a way to access the image object's URL string somehow, no?

    — commented 2 years ago by Sid K

I have the same issue as well, now using 1.6.1. I try to compare the image string of an image used in a tablerow and I get message = "invalid method 'toString:'"; I really need to be able to look at the current image to see if I need to change it. Any help on this anyone?

— answered 2 years ago by Mark Ross
answer permalink
1 Comment
  • Mark, the workaround I showed above can work pretty easily. When you set the image, just set another property with the image as a string:

    var iview = Ti.UI.createImageView({image:'checked.png', image_string:'checked.png'});
    if (iview.image_string == 'checked.png') {Ti.API.info('The image is checked.')};

    — commented 2 years ago by Dave Miller

Your Answer

Think you can help? Login to answer this question!