親(scrollView)を持つビューに画像を追加するという問題が発生しています。問題は、すべてのボタンにセレクターを設定しているにもかかわらず、ビューで最後に生成されたボタンのみがセレクターに応答し、メソッドを呼び出すことです。
for (int i = 0; i < [_wordsArray count]; i++) {
buttonFrame = CGRectMake(WORDSLEFTBOUNDARY, heightPlacement, [_detailSlider value], [_detailSlider value]);
UIButton *button = [[UIButton alloc] initWithFrame: buttonFrame];
// set the image for the button
[button setImage:[UIImage imageNamed:@"wordicon.png"] forState:UIControlStateNormal];
[button setTag:i]; // set tag identifier for the button
// add selector method 'buttonClickedAction' so that the method is called when a user
// clicks one of the buttons.
[button addTarget:self
action:@selector(buttonClickedAction:)
forControlEvents:UIControlEventTouchUpInside];
[_buttonsView addSubview: button]; // add newly created button as a subview to the buttonView
[_wordButtonArray addObject:button]; // insert newly created button into the wordButtonArray
if (i < [_dateDifferences count]) {
heightPlacement -= 60 + (60 * [[_dateDifferences objectAtIndex:i] intValue]);
}
}
したがって、上記のコードでは、各ボタンを作成し、ボタンの配列に追加する前にセレクターを追加します。ただし、何らかの理由でレスポンダー メソッド (buttonClickedAction) が呼び出されていません。