Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 7, 2010, 11:07 AM   #1
Slocum
macrumors newbie
 
Join Date: Feb 2010
UIImageView won't display

I can get UIImageView to display the image, if I set the image in the Interface Builder. But nothing shows when I set the parameters programmatically.

Here is the code:

ImageTestViewController.h:

Code:
#import <UIKit/UIKit.h>

@interface ImageTestViewController : UIViewController {
	UIImageView *imageView;
}
@property (nonatomic, retain) IBOutlet UIImageView *imageView;
@end
ImageTestViewController.m:

Code:
#import "ImageTestViewController.h"

@implementation ImageTestViewController

@synthesize imageView;

- (void)viewDidLoad {
	UIImage *image = [UIImage imageNamed:@"apress_logo.png"];
	imageView = [[UIImageView alloc] initWithImage:image];
    [super viewDidLoad];
}

- (void)viewDidUnload {
	imageView = nil;
	[super viewDidUnload];
}

- (void)dealloc {
	[imageView release];
    [super dealloc];
}

@end
I connected the UIImageView in the interface to the IBOutlet. The image is in the Resources. I still won't display. What have I done wrong?

Thanks.
Slocum is offline   0 Reply With Quote
Old Feb 7, 2010, 11:10 AM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
I am confused. If you have connected your IBOutlet to a UIImageView instance in Interface Builder then why are you creating a new UIImageView in your init? You are not altering the properties of the UIImageView you created in IB by doing this. You should be setting the image property of the instance you already have.

If you want to create your own UIImageView (if you do this delete then one in IB) then you should be adding it to a visible view hierarchy. The UIImageView you create is never added to a view that's on a visible window so will never be seen.
robbieduncan is offline   0 Reply With Quote
Old Feb 7, 2010, 12:18 PM   #3
Slocum
Thread Starter
macrumors newbie
 
Join Date: Feb 2010
Thank you. Boneheaded mistake.

I've changed it to:

Code:
- (void)viewDidLoad {
	UIImage *image = [UIImage imageNamed:@"apress_logo.png"];
	imageView.image = image;
    [super viewDidLoad];
}
and it works.

Last edited by kainjow; Feb 8, 2010 at 11:59 AM. Reason: code tags
Slocum is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Display won't stay on aligore iPhone Tips, Help and Troubleshooting 0 Apr 5, 2014 02:26 AM
UIImageView won't animate with UIImages of CGImage gwelmarten iPhone/iPad Programming 1 Oct 7, 2013 12:11 AM
UIImageView problem flashyx iPhone/iPad Programming 1 Mar 2, 2013 05:10 AM
how to display image in UIImageView in a specifc block of window in iphone mark.p iPhone/iPad Programming 1 Nov 27, 2012 12:36 PM
Folder Won't Display Image Previews (4th Display Option) trevor2522 Mac Basics and Help 5 Sep 11, 2012 09:59 AM

Forum Jump

All times are GMT -5. The time now is 09:47 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC