Reputation: 525
I am new to Objective C and Xcode so please be patient with me!! I have written a program that controls 5 buttons and 1 reset button. If any of the 5 buttons are pressed, they should all be disabled (greyed out) until the reset button is pressed. Here is my attempt:
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController{
IBOutlet UIButton *button1;
IBOutlet UIButton *button2;
IBOutlet UIButton *button3;
IBOutlet UIButton *button4;
IBOutlet UIButton *button5;
IBOutlet UIButton *resetButton;
}
@property(retain,nonatomic)UIButton *button1;
@property(retain,nonatomic)UIButton *button2;
@property(retain,nonatomic)UIButton *button3;
@property(retain,nonatomic)UIButton *button4;
@property(retain,nonatomic)UIButton *button5;
@property(retain,nonatomic)UIButton *resetButton;
- (IBAction)anyButtonPressed:(UIButton *)sender;
- (IBAction)resetPressed:(UIButton *)sender;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize button1, button2, button3, button4, button5, resetButton;
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
-(IBAction)anyButtonPressed{
button1.enabled = NO;
button2.enabled = NO;
button3.enabled = NO;
button4.enabled = NO;
button5.enabled = NO;
}
-(IBAction)resetPressed{
button1.enabled = YES;
button2.enabled = YES;
button3.enabled = YES;
button4.enabled = YES;
button5.enabled = YES;
}
@end
But it says incomplete implementation next to ViewController and when I press a button in the simulator, it crashes. Help me please? Also please suggest any easier ways to implement this!
Upvotes: 1
Views: 847
Reputation: 21967
Your button action method signatures are not correct in your implementation. Change your code to:
-(IBAction)anyButtonPressed:(UIButton *)sender {
button1.enabled = NO;
button2.enabled = NO;
button3.enabled = NO;
button4.enabled = NO;
button5.enabled = NO;
}
-(IBAction)resetPressed:(UIButton *)sender {
button1.enabled = YES;
button2.enabled = YES;
button3.enabled = YES;
button4.enabled = YES;
button5.enabled = YES;
}
Upvotes: 1