简体   繁体   中英

Displaying image when button clicked

I've build this keyboard and in the picture you can see it, it's the number 1 but I want to it become number 2.

I write with taking the title of every button so button A is titled A and when clicked it will display A in the large label that I have over those empty boxes, the empty boxes are UIview.

Does someone knows in which way to get this working do I have to use different layers? or whatever because I don't know.

hope someone can tell me here is the picture:

http://img213.imageshack.us/img213/4500/questionow.png

thanks

EDIT

This is what I got now .h

    IBOutlet UIImageView *imageview1;
    IBOutlet UIImageView *imageview2;
    IBOutlet UIImageView *imageview3;
    IBOutlet UIImageView *imageview4;
    IBOutlet UIImageView *imageview5;
    IBOutlet UIImageView *imageview6;
}

-(IBAction)showA;
-(IBAction)showB;
-(IBAction)showC;
-(IBAction)showD;
-(IBAction)showE;
-(IBAction)showF;
-(IBAction)showG;
-(IBAction)showH;
-(IBAction)showI;
-(IBAction)showJ;
-(IBAction)showK;
-(IBAction)showL;
-(IBAction)showM;
-(IBAction)showN;
-(IBAction)showO;
-(IBAction)showP;
-(IBAction)showQ;
-(IBAction)showR;
-(IBAction)showS;
-(IBAction)showT;
-(IBAction)showU;
-(IBAction)showV;
-(IBAction)showW;
-(IBAction)showX;
-(IBAction)showY;
-(IBAction)showZ;

.m

-(IBAction)showA {

UIImage *img = [UIImage imageNamed:@"A.png"];

[imageview1 setImage:img];

}

-(IBAction)showB {

UIImage *img = [UIImage imageNamed:@"B.png"];

[imageview1 setImage:img];  

}

Etc.

got UIImageview over the empty box and the first letters are shown very nice

Watched some tutorials on mutable arrays but still not sure how to implant it in my code.

Would it be a mutable array with imagevie1, 2,3,4,5,6?

hope you can help me out again

This is more about organizing your thoughts than actually technical stuff.

1) Check how many boxes are filled, so you know what's the next box to be filled.

2) Have a way to access each box.

Edit 1: Building the Data Source

This is just a way to get your started:

1) Start by creating an NSMutableArray.

2) When you click any button, using the size of your NSMutableArray, you can automatically know where the image should be placed:

myArray count = 0 => UIImageView 0 needs to be filled
myArray count = 1 => UIImageView 1 needs to be filled
myArray count = 2 => UIImageView 2 needs to be filled
myArray count = 3 => UIImageView 3 needs to be filled

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM