ボタンのクリック時にラベルのテキストを変更しようとすると、コードはコンパイルされますが、機能しません。ボタンをクリックしても何も起こりません。現在、ボタン 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
ありがとうございました