UIButton のアクションに少し問題があります。プログラムで 4 つのボタンを作成していますが、TouchUpInside イベントを発生させることができません。
私はSOを読みましたが、まだ問題があるので、どんなポインタでも大歓迎です!
ボタンとそのアクションを作成して設定するコードは次のとおりです。
UIButton *btn;
float newWidth = 10;
for (int i = 0; i < _btnImages.count; ++i) {
btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
CGRect imageFrame = CGRectMake(/*X*/newWidth, /*Y*/height - 80, 65, 65);
btn.frame = imageFrame;
btn.tag = i;
[btn setBackgroundImage:[UIImage imageNamed:[_btnImages objectAtIndex:i]] forState:UIControlStateNormal];
[btn addTarget:self
action:@selector(btnSelected:)
forControlEvents:UIControlEventTouchUpInside];
[btn setEnabled:true];
[self addSubview:btn];
newWidth = newWidth + 75;
}
ここに btnSelected メソッドがあります:
-(void)btnSelected:(UIButton *)button
{
NSLog(@"Button %ld Clicked",(long int)[button tag]);
}