You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

UIImageView setImage doesn't work with presentModelViewController?

I cannot for the life of me get a UIImageView declared on a view controller that is displayed modally to display anything other than the default image I have selected for the UIImageView. My View is declared through IB and hooked in to the controller. The viewcontroller is init'ed with the nib file containing the UI elements. Other properties of UI elements on the view get set correctly; as well as IBActions that are declared in the nib.

Any thoughts? I have tried putting my initialization code in both viewDidLoad and initWithNibName and neither way works. Also, calling setImage on my UIImageView in other places in my controller doesn't achieve anything.

On a related note, why don't UIImageView's respect the contentMode property when displaying an image that isn't exactly the aspect ratio of the UIImageView?

Thanks,
-MrB

MacBook, Mac OS X (10.5.6)

Posted on Feb 22, 2009 3:03 PM

Reply
Question marked as Top-ranking reply

Posted on Feb 22, 2009 5:50 PM

The first thing to look for is whether you're sending the setImage message to the UIImageView instance you expect. Use NSLog to check for a nil pointer in the same place you're trying to set the image. Obj-C loves to make newbies crazy by sending messages to nil pointers without any warning or other problem. If the pointer is nil, double check the IBOutlet connection to the UIImageView in IB.

If the pointer isn't nil, make sure you didn't reset it someplace in your code. It's easy to get confused and alloc another instance of UIImageView which would then be happy to accept the image message while the view which is actually visible remains unchanged. You might try sending a different message to the view, e.g. resetting the frame, as a sanity check.

When you're convinced the message is going to the right view, check the line that sends the message; it should look something like this:

[[imageView setImage:[UIImage imageNamed:@"Picture.jpg"]];
2 replies
Question marked as Top-ranking reply

Feb 22, 2009 5:50 PM in response to mrbelk

The first thing to look for is whether you're sending the setImage message to the UIImageView instance you expect. Use NSLog to check for a nil pointer in the same place you're trying to set the image. Obj-C loves to make newbies crazy by sending messages to nil pointers without any warning or other problem. If the pointer is nil, double check the IBOutlet connection to the UIImageView in IB.

If the pointer isn't nil, make sure you didn't reset it someplace in your code. It's easy to get confused and alloc another instance of UIImageView which would then be happy to accept the image message while the view which is actually visible remains unchanged. You might try sending a different message to the view, e.g. resetting the frame, as a sanity check.

When you're convinced the message is going to the right view, check the line that sends the message; it should look something like this:

[[imageView setImage:[UIImage imageNamed:@"Picture.jpg"]];

UIImageView setImage doesn't work with presentModelViewController?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.