不完整的实现xcode按钮禁用按钮

时间:2012-11-12 23:50:12

标签: iphone objective-c ios xcode ios6

我是Objective C和Xcode的新手,所以请耐心等待我!我编写了一个控制5个按钮和1个重置按钮的程序。如果按下5个按钮中的任何一个,则应按下所有按钮(灰色),直到按下重置按钮。这是我的尝试:

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旁边的实现不完整,当我按下模拟器中的按钮时,它会崩溃。请帮帮我?另外,请建议任何更简单的方法来实现这一点!

1 个答案:

答案 0 :(得分:1)

您的按钮操作方法签名在您的实施中不正确。将您的代码更改为:

-(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;
}