当我尝试在单击按钮时更改标签的文本时,代码会编译但它不起作用。我单击按钮,没有任何反应。目前,我只是试图在按下按钮solveButton时在标签x1Label上显示“错误”。你能帮我修一下吗?
。H
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize errorLabel;
@synthesize aField, bField, cField;
@synthesize x1Label, x2Label;
@synthesize solveButton;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
aField.delegate = self;
bField.delegate = self;
cField.delegate = self;
aField.keyboardType = UIKeyboardTypeNumberPad;
bField.keyboardType = UIKeyboardTypeNumberPad;
cField.keyboardType = UIKeyboardTypeNumberPad;
NSString *str = @"car";
errorLabel.text = str;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[aField resignFirstResponder];
[bField resignFirstResponder];
[cField resignFirstResponder];
return YES;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[aField resignFirstResponder];
[bField resignFirstResponder];
[cField resignFirstResponder];
}
- (IBAction)solveButton:(id)sender
{
errorLabel.text = @"Error";
}
@end
.m
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UITextFieldDelegate>
{
IBOutlet UITextField *aField, *bField, *cField;
}
@property (weak, nonatomic) IBOutlet UILabel *errorLabel;
@property (strong, nonatomic) IBOutlet UITextField *aField;
@property (strong, nonatomic) IBOutlet UITextField *bField;
@property (strong, nonatomic) IBOutlet UITextField *cField;
@property (weak, nonatomic) IBOutlet UILabel *x1Label;
@property (weak, nonatomic) IBOutlet UILabel *x2Label;
@property (weak, nonatomic) IBOutlet UIButton *solveButton;
@end
谢谢