以下のコードのようなボタンを作成しましたが、ログに応答しません ("ha" と表示されるはずです)。最も奇妙な部分は、この正確なコードをコレクションビュー内で機能させることができたが、通常はビューコントローラーでは機能しなかったことです。ボタンを押して「myAction」を押すと何が間違っていますか?
-(void)viewDidLoad {
UIButton *buttonz = [UIButton buttonWithType:UIButtonTypeCustom];
buttonz.frame = CGRectMake(160, 0, 160, 30);
[buttonz setTitle:@"Charge" forState:UIControlStateNormal];
[buttonz addTarget:self action:@selector(myAction:) forControlEvents:UIControlEventTouchUpInside];
[buttonz setEnabled:YES];
[buttonz setBackgroundColor:[UIColor blueColor]];
//add the button to the view
[backImageView addSubview:buttonz];
}
-(void)myAction:(id)sender {
NSLog(@"ha");
[self resignFirstResponder];
NSLog(@"ha");
}