UIImageView と UIButton を追加した Interface Builder で UITableViewCell を作成しました。UIButton にアウトレットを与え、イベント セット内のタッチアップを使用して IBAction に接続しました。すべてが接続されているように見えたので、このメソッドを呼び出すと想定しました。
- (IBAction)pressedCheckbox:(id)sender {
[sender setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
NSLog(@"clicked check");
}
接続タブを確認すると、アウトレットとアクションのすべてが正しく設定されています。エラーは発生しませんが、アプリをプレビューするときに UITableViewCell 内のそのボタンをクリックしても何も起こらず、ログには何も表示されません。
UITableViewCellにあるボタンをクリックできない理由についてのアイデアは?
編集:
cellForRowAtIndexPath のコード:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
if (indexPath.section == 0) {
switch (indexPath.row) {
case 0:
cell = topCell;
break;
case 1:
cell = cell1;
break;
}//end switch
}//end if
return cell;
}