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
Sort By: 
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"]];
Reply

Feb 22, 2009 6:11 PM in response to RayNewbie

Dude, you are like my own personal cocoa touch answer-man. I would have bet my house that I made the IB outlet from the nib to the controller, but when I went back and like septuple-checked it, sure enough it wasn't set up.

Thanks,
-MrB
Reply

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

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.