tableView:accessoryButtonTappedForRowWithIndexPath:
の行にアクセサリ ビューが設定されている場合、メソッドは呼び出されないとドキュメントに記載されていindexPath
ます。このメソッドは、プロパティが有効な場合にのみ呼び出され、accessoryView
プロパティをnil
使用および設定しaccessoryType
て組み込みアクセサリ ビューを表示する場合にのみ呼び出されます。
私が理解しているように、accessoryView
相互accessoryType
に排他的です。を使用するaccessoryType
と、システムは期待どおりに呼び出しtableView:accessoryButtonTappedForRowWithIndexPath:
ますが、それ以外の場合は自分で処理する必要があります。
Apple がこれを行う方法Accessory
は、SDK のサンプル プロジェクトに示されています。cellForRowAtIndexPath
dataSource デリゲートのメソッドで、ターゲット/アクションをカスタム アクセサリ ボタンに設定します。indexPath
をアクションに渡すことができないため、補助メソッドを呼び出して対応するものを取得しindexPath
、結果をデリゲート メソッドに渡します。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
...
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
...
// set the button's target to this table view controller so we can interpret touch events and map that to a NSIndexSet
[button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];
...
cell.accessoryView = button;
return cell;
}
- (void)checkButtonTapped:(id)sender 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){
[self tableView: self.tableView accessoryButtonTappedForRowWithIndexPath: indexPath];
}
}
何らかの理由で、あなたの設定はaccessoryViewのケースに当てはまるようです。accessoryType
Interface Builder を使用する代わりに with コードを設定しようとしましたか?