1

I have a UIButton and a UIImageView. The UIButton and UIImageView are on different views in storyboard. What I want to happen is when the button is pressed, it switches views and the UIImageView switches to a different image. Right now, the view changes, but the UIImageView doesn't change.

Here is the ViewController.h file

#import <UIKit/UIKit.h>
#import "Player.h"
#import "Space.h"

@interface ViewController : UIViewController
{
    IBOutlet UIImageView* space0_0;
    Player* m_player;
    Space* m_spaces[16][16];
}
-(IBAction)startGame;


@end

The reason there is an array of spaces is that I want there to eventually be a 16x16 board of UIImageViews. Right now I only have 1 image view just to get the first one working before moving on

Here is the IBAction connected to the button that is supposed to change the UIImageView

-(IBAction)startGame
{
    [m_spaces[0][0] setImageView:space0_0];
    [m_spaces[0][0] displaySpace];
}

I made a class called Space. Here is the Space.h file

#import <Foundation/Foundation.h>

@interface Space : NSObject
{
    UIImageView* m_imageView;
}

-(void)setImageView:(UIImageView*)imageView;
-(UIImageView*)imageView;
-(void)displaySpace;
@end

Here is the Space.m file

#import "Space.h"

@implementation Space

-(void)setImageView:(UIImageView*)imageView
{
    m_imageView = imageView;
}

-(UIImageView*)imageView
{
    return m_imageView;
}
-(void)displaySpace
{
    m_imageView.image = [UIImage imageNamed:@"player.png"];
}

@end

Can anyone tell me where I'm going wrong here? The only problem is that the UIImageView's image does not change.

Edit: when I change the startGame method to:

-(IBAction)startGame;
{
space0_0.image = [UIImage imageNamed:@"player.png"];
}

So the problem is somewhere in my Space class.

  • hi what is space0_0? where you created the object ? and [m_spaces[0][0] setImageView:space0_0]; [m_spaces[0][0] displaySpace]; in the array your not iterated so your getting the same image only.... pls update your Question with this details... – Arun Sep 20 '12 at 05:02

0 Answers0