hi
i am new to iphone app dev.
i am trying to make a NSArray with couple of image in it. images are stored in app directory. i want to load all images and display images by accessing that array using index. so far i am using doing this to load images
that's what i was thinking too
i used it because i saw someone using the code this way
so can anyone guide me how to add images to an array, any online link would be great or just give an example
thank you
This is where we call on our good friend the for loop. If your images are named in a logical way (hatAnimation1.jpg, hatAnimation2.jpg etc) it is easy to set up a for loop to do this; I do this frequently.
thanks for replying so quickly.
as i said before i am not an expert in programming
i am thinking of using loop but couldn't think of a way to use different filename in one loop. can you give me a hint please
thank you
You can find information on the docs on for loop pretty easily if you search around in "help" in xcode. I don't have my mac in front of me so I'll do the best I can from memory.
Now what this does will load in the images called hatAnimation1.png, hatAnimation2.png etc up to hatAnimation9.png.
Again, I am writing from memory here so my syntax might be slightly off but this is the jist; of course you must have your NSMutable Array allocated and released as usual in addition to the things above. Hope this helps!
sorry for bothering u again
i implement the code you posted and now i am getting a warning
"UIImage may not respond to +imageWithContentsOf FIleathForResourcesf Type:"
any suggestion
I may have typoed. There definitely is a method like that for UIImage. Highlight the phrase UIImage in xCode and open research assistant; then click on "view class notes" or whatever it says and look through the class methods for one similar to what I wrote; it definitely exists.
I'm not sitting in front of my mac so I probably missed a bracket or typoed a word.
NSBundle is telling where to look for the file. The bundle is basically all the resources that are included with your app (images, sounds, files, etc).
If there are no typoes I don't know why it wouldn't work. Usually when you get errors like the one you listed it is because you are failing to include a header file or some such...but UIImage is a fairly essential class so it should be covered by the default headers when you start a new project; are you in some kind of custom object with this code or did you mess with the headers?
I went for an inefficient way of using imagenamed
and i can now run the code and see the images but program crashed after 2-3 seconds...
[UIImage imageNamed:@......]
any thoughts
thanks
I may have typoed. There definitely is a method like that for UIImage. Highlight the phrase UIImage in xCode and open research assistant; then click on "view class notes" or whatever it says and look through the class methods for one similar to what I wrote; it definitely exists.
I'm not sitting in front of my mac so I probably missed a bracket or typoed a word.
I think you were missing a bracket here and there (in case anyone else is playing along at home )
I'm following along. Have tried this a couple different ways, but both present an error. The following gives me three "error: syntax error before ';' token" errors.
And here, I've had trouble with this method. The method above seems to work better. I'm not sure why, but, at least when there are a lot of images, the technique below crashes after a while.