2011-05-13 6 views
0

"アクセサリー"のサンプルコードを使用して、テーブルにカスタムアクセサリーイメージを作成しました。テーブルは画像を適切にレンダリングしますが、accessoryButtonTappedForRowWithIndexPathメソッドに私を連れて行くはずの画像をクリックすると何らかの理由でindexPathがnilなので何も起こりません。あなたは自分のUITableViewDelegatetableView: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]; 
    } 
} 

答えて

1

:indexPathをチェックし、このメソッドを参照してください?

+0

カスタムアクセサリイメージを使用できるように、このメソッドを使用する必要があります(アップルの「アクセサリ」のサンプルコードを参照)。そのサンプルコードでは、AppleはUITableViewControllerを親クラスとして使用していますが、これにはtableView ivarがあります。私はtableView ivarのないUIViewControllerクラスを使用しています。 UIViewControllerクラスのtableView ivarを作成できますか? –

+1

ええ、Interface Builderでテーブルを作成する場合は、IBOutletを作成してください。コードで作成する場合は、ヘッダーファイルにivarを宣言してください。 – edc1591

関連する問題