Results 1 to 5 of 5

Your favorite Apple, iPhone, iPad, iOS, Jailbreak, and Cydia site.


Thread: UIImage:imageNamed - where does it look for images?

  1. #1
    Default UIImage:imageNamed - where does it look for images?
    hi,
    I'm pretty new to iPhone development (or cocoa development for that matter) and I recently tried setting up a toolbar. It works, the only problem is it doesn't show the images for every toolbarItem. I tested a little and found out that my UIImage Object returned nil.
    Now my question: Where does UIImage:imageNamed look for images?
    I put an image called "FeaturedOff.png" into the main project directory (so the directory where the main.m lies) and then I tried

    [UIImage imageNamed:@"FeaturedOff.png"]

    but it just returns nil. same for other images. why?
    finder shows the images just fine so I guess it has nothing to do with my images being broken or something.

    thanks :-)

  2. #2
    The code you listed is executed when your program is running.

    Did you copy your png into the Application bundle that you put on the iPhone when running your test?
    Starlight Computer Wizardry
    Pocket-sized Development
    Follow me on twitter: @NetMage

  3. The Following User Says Thank You to NetMage For This Useful Post:

    BlackWolf (2008-03-15)

  4. #3
    What's Jailbreak?
    Join Date
    Feb 2008
    Location
    Basel, Switzerland, Europe
    Posts
    8
    Thanks
    0
    Thanked 1 Time in 1 Post
    Hey.

    Try this:
    On the left side in XCode, where all your class files etc. are listed, create a new group (=folder) for example "images". Then rightclick on the new group and select "From existing File" or something like that and add your *.png file. Then it should work:

    [UIImage imageNamed:@"NameOfYourPicture.png"]

    I am not sure if this is the best solution, but I saw it in one of the sample codes on the iphone dev center.

  5. The Following User Says Thank You to DrummerB For This Useful Post:

    BlackWolf (2008-03-15)

  6. #4
    I think what your problem is that your .png is in the directory in Finder but, it's not added to your project. What you need to do is single click on any item in your project, then go up to the ACTION pull down tab and select ADD, then EXISTING FILES. Once you have done this select your .png's. This will add your .png's to the project, allowing your code to discover them. I believe this is what DrummerB was getting at, I just wanted to help make it more clear.

    Hope this helps,

    Swell

  7. The Following User Says Thank You to swell For This Useful Post:

    BlackWolf (2008-03-15)

  8. #5
    yeah, thank you very much guys, it works perfectly fine :-)

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •