Brendon
Brendon

Reputation: 177

Changing image in different view

I am attempting to change the character image in the game that I am creating but I am having some issues. I have a view controller where I will have all of the characters as their own buttons, and by selecting a button it should change the character image in the GameViewController

change.h

- (IBAction)charOne:(id)sender;

change.m

- (IBAction)charOne:(id)sender 
{

    GameViewController *changeView = [GameViewController game];
    UIImageView *Romo = [GameView changeView];

    [ChangeView setImage:[UIImage imageNamed:@"testOne.png"]];

    NSLog(@"Test");

}

GameViewController.m

{
    IBOutlet UIImageView *changeView;
}

@property (strong, nonatomic) IBOutlet UIImageView *changeView;

This code isn't working for me, I do not receive an error message but nothing is changed after the image is selected.

On the GameViewController the UIImage name that I am attempting to change the image for is named Romo. Any help will be appreciated

Upvotes: 1

Views: 47

Answers (1)

brandonscript
brandonscript

Reputation: 73024

try :

[Romo setImage:[UIImage imageNamed:@"testOne.png"]];

instead of :

[ChangeView setImage:[UIImage imageNamed:@"testOne.png"]];

You're calling the setImage method on a class rather than an instance of a class. Since Romo is the instance of UIImageView you want to affect (which is a reference pointer to the UIImageView on your game view controller), that should be the instance you affect.

Also, bad practice to name instances starting with a capital letter -- they turn out looking like classes.

Upvotes: 2

Related Questions