images on iphone
i'm running circles right now…
i try to show an image on an iphone. but it doesn't work - obviously.
i see the images in the kitchensink app, so it is working. but not with my app. here's the code i use:
http://pastebin.com/ZMRdKvWZ
the images are in /Resources/images
8 Answers
-
thanks, but i just found out. although i would like your comment on this:
app.js
the interesting part is: url:"view/ErmittlungAltanlage.js" -> relativeErmittlungAltanlage.js (i shortened it) -> as you can see, all references to images are as well relative.
with absolute urls, i couldn't get it to work on iphone. -> no problem on android though.
in app.js, i used: url:"/view/ErmittlungAltanlage.js" -> absolute
and in ErmittlungAltanlage.js i used image:"/images/someimage.png" -> absolute url as well.any thoughts on that?
thx
ps.: i'm using 1.4.3 sdk for iphone
-
your path for the images in incorrect should be
Titanium.UI.createImageView({ url:"images/SmallHouse.png", touchEnabled:false, left:77, top:65});
remove the first "/"
-
Marcin
In contrast to the other answer, I think your image paths are fine - the preceding forward-slash is equivalent to the Resources folder, so as long as your images are in
Resources/images/
then there should be no problem. In fact, I always use absolute paths like these.However, you are using the url property for createImageView, which is deprecated, rather than the image property. Hence, code like:
var iconOil = Titanium.UI.createImageView({ url:"/images/SmallHouse.png", touchEnabled:false, left:77, top:65 });
should be:
var iconOil = Titanium.UI.createImageView({ image:"/images/SmallHouse.png", touchEnabled:false, left:77, top:65 });
Hope this resolves your issue. If not, let us know
-
I got this approach to work
image: "../images/SmallHouse.png",
I believe that path needs to be relative to where the .js file is located. I just tested this and it appears to be working, let me know how it turns out
in response to Hal's comments about using relative paths, this will also work
var path = Titanium.Filesystem.resourcesDirectory + Titanium.Filesystem.separator; Titanium.API.info("--> " + path); var imageView = Titanium.UI.createImageView({ image: path + "images/SmallHouse.png", touchEnabled:false, left:77, top:65});
-
Marcin
As your pastebin is long, and contains lots of references to images that will cause exceptions if we try to run it in our environment, if you like you could zip the Resouces folder and upload it somewhere. Then someone can take a look and get this working for you.
Cheers
-
test one
var imageView = Titanium.UI.createImageView({ image: "images/appcelerator_small.png", touchEnabled:false, left:77, top:65});
outputs this
[ERROR] Failed to load image: file://localhost/Users/aaronksaunders/dev/projects/titanium/test1/Resources/view/images/appcelerator_small.png, Error: Error Domain=ASIHTTPRequestErrorDomain Code=1 "A connection failure occurred" UserInfo=0x8c0f260 {NSUnderlyingError=0x8c0dfe0 "The operation couldn’t be completed. Connection refused", NSLocalizedDescription=A connection failure occurred}
test two
var imageView = Titanium.UI.createImageView({ image: "/images/appcelerator_small.png", touchEnabled:false, left:77, top:65});
outputs this
[ERROR] Failed to load image: file://localhost/images/appcelerator_small.png, Error: Error Domain=ASIHTTPRequestErrorDomain Code=1 "A connection failure occurred" UserInfo=0x8c0f9a0 {NSUnderlyingError=0x8c05df0 "The operation couldn’t be completed. Connection refused", NSLocalizedDescription=A connection failure occurred}
it is not a problem in his code, it is a problem in the way the imageView is loading the url/image. The only way to make it work, at this time, is to specify the full path of the image or to use the relative path from the location of the .js loading the imageView.
Maybe this is a bug??
-
well, i think this is definitly a design flow.
there is no reason why android should get the paths right while the iphone doesn't.
it just doesn't make sense. -
Marcin
I think I have found the reason. Take a look at ticket #1986. If you sign up with LH, and watch the ticket, it will email you any developments on the status of the issue.