btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [btn setTag:BTN]; [btn setFrame:CGRectMake(200, 5, 50, 50)]; [btn setTitle:@"t" forState:UIControlStateNormal]; [btn addTarget:self action:@selector(onCellButtonPushed:event:) forControlEvents:UIControlEventTouchUpInside]; [cell.contentView addSubview:btn];
以下のようにしてどのcellのボタンが押されたか判定する。
- (void)onCellButtonPushed:(UIButton *)button event:(id)event { NSSet *touches = [event allTouches]; UITouch *touch = [touches anyObject]; CGPoint currentTouchPosition = [touch locationInView:self.tableView]; NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition]; if (indexPath != nil) { } }