Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Setting Images

Setting Images
Thread Tools
Mac Enthusiast
Join Date: Oct 2001
Status: Offline
Reply With Quote
Jul 13, 2002, 09:57 PM
 
Im trying to programatically set the image of an NSButton or even an NSImage view in a prefPane I am working on. I have added the image to my project. It is checked in project builder for inclusion in the bundle, I have made an outlet in IB, I have connected the outlet to the image view. I have set the image in IB to be centered. I have made the Image View huge in the hopes that perhaps the image was displaying but perhaps out of view. I have even made the Image View editable and successfully dropped the image into the well durring run. I have declared the outlet in PB. Heres my code.

[updateImage setImage:[NSImage imageNamed:@"flagged"]];

The image is a tiff although I've tried a dozen images of various types.

Why do I suck?
3R1C
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Jul 14, 2002, 02:07 AM
 
1. Find out if you can actually load the image:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">NSImage *myImage = [NSImage imageNamed:@&quot;flagged&quot;];
NSLog(@&quot;image: %@&quot;, [myImage description]);</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">2. Find out if the NSImageView instance actually exists and can be talked to. Log its description, or set its bezel style, or ask for some attribute it has and log that.

One possible problem that comes to mind is that you might be loading the nib more than once: are you manually loading the nib via loadNibNamed:? Are you sure you go through that code path only once?
Rick Roe
icons.cx | weblog
     
3R1C  (op)
Mac Enthusiast
Join Date: Oct 2001
Status: Offline
Reply With Quote
Jul 14, 2002, 06:03 AM
 
I figured it out. The deal was that setImage: looks in the main bundle for the image, but I'm making a prefPane so my image isnt in the main bundle. Heres what I did instead:

[updateImage setImage:[[NSImage alloc] initWithContentsOfFile:[[NSBundle bundleForClass:[self class]] pathForImageResource:@"flagged"]]];

On a side note, Thanx to ya'll, I'm really starting to get this programming stuff. I read somewhere that apples goal was to make devs out of users. I've been a user for 25 years and in the past I tried many times to learn to program, but until now I found it impossible. Thanx apple. =)
3R1C
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 10:02 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2