Hi I am new to Xcode development for the iPhone and am stuck on implementing a history function.
In layman’s terms I have
4 buttons (each with its own unique image)
(button 1)
(button 2)
(button 3)
(button 4)
and 5 imageviews
(imageview position 1)
(imageview position 2)
(imageview position 3)
(imageview position 4)
(imageview position 5)
Each time a button is clicked (upto 5 times) i need it to be displayed at the appropriate image view.
i.e if button 4 was pressed first it would be displayed at image view 1
if button 3 was pressed second it would be displayed at image view 2 etc.
I would really appreciate some assistance or push in the right direction.
Thanks in advance
Update Code:
viewcontroller.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController {
IBOutlet UIImageView *imageview_history_1;
IBOutlet UIImageView *imageview_history_2;
IBOutlet UIImageView *imageview_history_3;
IBOutlet UIImageView *imageview_history_4;
IBOutlet UIImageView *imageview_history_5;
}
// I would think this could be consolidated into one function
-(IBAction)showhistory_1;
-(IBAction)showhistory_2;
-(IBAction)showhistory_3;
-(IBAction)showhistory_4;
-(IBAction)showhistory_5;
@end
#import ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
// function to add to history
// Need an if/for statement???
// On button event 1 display result at image view_history 1,
// On button event 2 display result at image view_history 2.
- (IBAction)showhistory_1 {
UIImage *img = [UIImage imageNamed:@"button1"];
[imageview_history_1 setImage:img];
}
@end
//I’m stuck at creating the function. Thanks again.
First, in your xib, give each button a tag number to easily identify it:
Let’s say that you give button1 a tag of 1, button2 is tag 2, etc.
I would then change your UIButton actions to all point to the same function:
.h:
.m: