1
我是Objective C和Xcode的新手,請耐心等待我!我寫了一個程序來控制5個按鈕和1個重置按鈕。如果按下了5個按鈕中的任何一個,則應該全部禁用(灰顯),直到按下重置按鈕。這裏是我的嘗試:不完整的實現xcode按鈕來禁用按鈕
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
但它說完全執行旁邊的ViewController,當我在模擬器中按下一個按鈕,它崩潰。請幫幫我?另外請建議任何更簡單的方法來實現這一點!
哇這麼簡單的事情我錯過了......謝謝! – stellarowl12