0
"アクセサリー"のサンプルコードを使用して、テーブルにカスタムアクセサリーイメージを作成しました。テーブルは画像を適切にレンダリングしますが、accessoryButtonTappedForRowWithIndexPathメソッドに私を連れて行くはずの画像をクリックすると何らかの理由でindexPathがnilなので何も起こりません。あなたは自分のUITableViewDelegate
でtableView:accessoryButtonTappedForRowWithIndexPath:
を使用することはできませんなぜiOS indexPath is nil(カスタムアクセサリーイメージ)
- (void)accessoryButtonTapped:(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];
}
}
カスタムアクセサリイメージを使用できるように、このメソッドを使用する必要があります(アップルの「アクセサリ」のサンプルコードを参照)。そのサンプルコードでは、AppleはUITableViewControllerを親クラスとして使用していますが、これにはtableView ivarがあります。私はtableView ivarのないUIViewControllerクラスを使用しています。 UIViewControllerクラスのtableView ivarを作成できますか? –
ええ、Interface Builderでテーブルを作成する場合は、IBOutletを作成してください。コードで作成する場合は、ヘッダーファイルにivarを宣言してください。 – edc1591