配列を使用して設定される詳細開示ボタンを作成しています。ただし、accessoryButtonTappedForRowWithIndexPath: 関数がクラスで呼び出されません。これはデリゲートTableviewDelegate
ですTableviewDatasource
。
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
NSLog(@"reaching accessoryButtonTappedForRowWithIndexPath:");
[self performSegueWithIdentifier:@"modaltodetails" sender:[self.eventsTable cellForRowAtIndexPath:indexPath]];
}
NSLog がコンソールに出力されないため、関数が呼び出されていないと考えられます... これはもちろん、セルを選択したときです。以下のスクリーンショットは、セルの設定方法を示しています。
ベストアンサー1
ドキュメントによると、この方法はtableView:accessoryButtonTappedForRowWithIndexPath:
の行にアクセサリ ビューが設定されている場合は、メソッドは呼び出されませんindexPath
。 メソッドは、accessoryView
プロパティが でありnil
、accessoryType
プロパティを使用して組み込みアクセサリ ビューを表示するように設定した場合にのみ呼び出されます。
私の理解では、accessoryView
と はaccessoryType
相互に排他的です。 を使用する場合accessoryType
、システムはtableView:accessoryButtonTappedForRowWithIndexPath:
期待どおりに を呼び出しますが、他のケースは自分で処理する必要があります。
Apple がこれを実行する方法は、Accessory
SDK のサンプル プロジェクトに示されています。dataSourcecellForRowAtIndexPath
デリゲートのメソッドで、カスタム アクセサリ ボタンにターゲット/アクションを設定します。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 の場合に該当するようです。Interface accessoryType
Builder を使用する代わりに、コードを使用して設定してみましたか?