ユーザーが戻るボタンを押したときに非表示にしたいテキストフィールドがあります。テキストフィールドはInterfaceBuilderで作成され、.hファイルにテキストフィールドデリゲートを追加し、テキストフィールドのデリゲートをファイル所有者として設定しました。
@interface ProfileEdit : UIViewController<UITextFieldDelegate>{
UITextField *textfield1;
UITextField *textfield2;
UITextField *textfield3;
}
- (void)viewDidLoad
{
textfield1 = [[UITextField alloc] initWithFrame:CGRectMake(20, 49, 164, 31)];
[textfield1 setDelegate:self];
[textfield1 setAutocorrectionType:UITextAutocorrectionTypeNo];
[self.view addSubview:textfield1];
textfield2 = [[UITextField alloc] initWithFrame:CGRectMake(20, 124, 164, 31)];
[textfield2 setDelegate:self];
[textfield2 setAutocorrectionType:UITextAutocorrectionTypeNo];
[self.view addSubview:textfield2]
textfield3 = [[UITextField alloc] initWithFrame:CGRectMake(20, 198, 164, 31)];
[textfield3 setDelegate:self];
[textfield3 setAutocorrectionType:UITextAutocorrectionTypeNo];
[self.view addSubview:textfield3];
[super viewDidLoad];
}
また、touchupinsideイベントがトリガーされるバックグラウンドにボタンを配置しました
-(IBAction)hideKeyboard:(id)sender{
[textfield1 resignFirstResponder];
[textfield2 resignFirstResponder];
[textfield3 resignFirstResponder];
}
これは正常に機能し、エラーは発生しません。しかし、これのために
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[self hideKeyboard:nil];
return YES;
}
main.mでEXC_BAD_ACCESSを取得します。私はこれに数日間立ち往生していて、なぜこれが起こっているのか分かりません。