indexPath
の行にアクセサリビューが設定されているときに、tableView:accessoryButtonTappedForRowWithIndexPath:
メソッドが呼び出されていないことを示しています。このメソッドは、accessoryView
プロパティがnilであり、accessoryType
プロパティを使用して組み込みのアクセサリビューを表示するときにのみ呼び出されます。私が理解しているように、accessoryView
とaccessoryType
は互いに排他的です。 accessoryType
を使用すると、システムはtableView:accessoryButtonTappedForRowWithIndexPath:
を予期して呼び出しますが、自分で処理する必要があります。
Appleがこれを行う方法は、SDKのAccessory
サンプルプロジェクトに示されています。 dataSourceデリゲートのcellForRowAtIndexPath
メソッドでは、ターゲット/アクションをカスタムアクセサリボタンに設定します。 1は、アクションに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];
}
}
、セットアップはに落ちるように見えますアクセサリーケースの場合。 Interface Builderを使用する代わりにaccessoryTypeをコードで設定しようとしましたか?
出典
2012-10-10 01:14:15
Tom
は、あなたが適切なクラスへのdataSource&デリゲートを接続しますか? ' - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath' メソッドが呼び出されますか? – Thermometer
はい(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPathが呼び出されています。 – jimbob