Luai Kalkatawi
Luai Kalkatawi

Reputation: 1492

Xcode - How to change an image in UIImage View with only in one UIImageView and only one button

My code change the pic in two UIImageView with one button but I want only one UIImageView and only one button, how could I make it? Please help me. Thanks from now.

FirstView.h

#import <UIKit/UIKit.h>

@interface FirstView : UIViewController{

    IBOutlet UIImageView *firstImage;
    IBOutlet UIImageView *secondImage;

}
@property (nonatomic, retain) UIImageView *firstImage;
@property (nonatomic, retain) UIImageView *secondImage;

-(IBAction)buttonClicked;

@end

FirstView.m

#import "FirstView.h"

@implementation FirstView
@synthesize firstImage, secondImage;



- (IBAction)buttonClicked{

        if (secondImage.image==nil) {
            firstImage.image = nil; // this is useless, because the image is already in cache.
            secondImage.image = [UIImage imageNamed:@"Mini.png"];
        } else {
            secondImage.image = nil; // this is useless, because the image is already in cache.
            firstImage.image = [UIImage imageNamed:@"selo001.png"];
        }
    }
- (void)viewDidLoad {
    [super viewDidLoad];

    // when view loaded, load the first image only.

    firstImage.image = [UIImage imageNamed:@"selo001.png"];
}

Upvotes: 1

Views: 21018

Answers (1)

zaph
zaph

Reputation: 112857

I'm not quite shire what you are asking so this may not be what you want.

FirstView.h

#import <UIKit/UIKit.h>

@interface FirstView : UIViewController {
    IBOutlet UIImageView *onlyImageVIew;
    BOOL firstImage;
}
@property (nonatomic, retain) UIImageView *onlyImageVIew;
-(IBAction)buttonClicked;
@end

FirstView.m

#import "FirstView.h"

@implementation FirstView
@synthesize firstImage, secondImage;

- (IBAction)buttonClicked {
    if (firstImage == YES) {
        onlyImageView.image = [UIImage imageNamed:@"Mini.png"];
        firstImage == NO
    }
    else {
        onlyImageView.image = [UIImage imageNamed:@"selo001.png"];
        firstImage == YES
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];

    // when view loaded, load the first image only.
    firstImage = YES;
    onlyImageView.image = [UIImage imageNamed:@"selo001.png"];
}

Upvotes: 3

Related Questions