Subscribe ( )

iPhone Programming Tutorials

 

Forum

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

You must be logged in to post Login Register

Search 

Problem changing image property of UIImageView control

User Post

7:48 pm
May 26, 2009


StevenMiles

Noob

posts 1

1

Hi,

I'm stumped by a problem in a very simple test program.  I have two buttons and one UIImageView. Button #1 loads a .png into the image view, and Button #2 loads a different .png into the imageview.  It works fine initially, but when I try to *re-load* an image, that is, go back and forth between the buttons, or click on a button more than once, the program crashes.

Here is the entire code of the project:

the .m file:

@interface TestLoadImagesViewController : UIViewController {

IBOutlet UIImageView *imgShown;

}

@property (nonatomic, retain) UIImageView *imgShown;

-(IBAction)loadMichael:(id)sender;

-(IBAction)loadSasha:(id)sender;

the .h file:

#import “TestLoadImagesViewController.h”

@implementation TestLoadImagesViewController

@synthesize imgShown;

-(IBAction)loadMichael:(id)sender {

NSString *strNextImage = @”MikeHorse.png”;

UIImage *img = [UIImage imageNamed:strNextImage];

if (img != nil) {

[imgShown setImage:img];

[img release];

}

else {

//show me an alert here. The alert does not show during testing.

}

[strNextImage release];

}


-(IBAction)loadSasha:(id)sender {

NSString *strNextImage = @”SashaTeeth.png”;

UIImage *img = [UIImage imageNamed:strNextImage];

if (img != nil) {

[imgShown setImage:img];

[img release];

}

else {

// alert code here.

}

[strNextImage release];

}

Can anyone help with this?  I've searched the manuals and the 'Net with no luck.
/Steve

About the iCodeBlog forum

Currently Online:

4 Guests

Maximum Online: 44

Forums:

Groups: 2

Forums: 6

Topics: 330

Posts: 774

Members:

There are 734 members

There are 1 guests


Brandon has made 87 posts

Top Posters:

bobcubsfan - 54

crazyiez - 30

VertigoSol - 26

AdeC - 17

Uhu - 17

Administrator: Brandon | Moderators: VertigoSol


© - Version 3.1.4 (Build 357)