+ Reply
Results 1 to 5 of 5
  1. #1
    Livin the iPhone Life
    Join Date
    Dec 2007
    Posts
    1,460
    Thanks
    15
    Thanked 197 Times in 184 Posts

    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
    Developer NetMage's Avatar
    Join Date
    Aug 2007
    Location
    Virginia
    Posts
    1,292
    Thanks
    71
    Thanked 210 Times in 168 Posts

    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 (03-15-2008)

  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 (03-15-2008)

  6. #4
    Green Apple
    Join Date
    Aug 2007
    Posts
    98
    Thanks
    19
    Thanked 13 Times in 8 Posts

    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 (03-15-2008)

  8. #5
    Livin the iPhone Life
    Join Date
    Dec 2007
    Posts
    1,460
    Thanks
    15
    Thanked 197 Times in 184 Posts

    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