2

Appleの例のように、カスタムの開示ボタンを使用しようとしています。私は次のことをしています

- (void) customButtonTapped:(UIButton *)sender event: (id) event{

    NSSet *touches = [event allTouches];
    UITouch *touch = [touches anyObject];
    CGPoint currentTouchPosition = [touch locationInView:self.tableView];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];
    NSLog(@"index path %@", indexPath);
    if (indexPath != nil)
    {

    }


}

問題は、インデックスパスが常にnilであるということです。毎回必ず。他の誰かがこれに出くわしましたか?

編集 これは私がボタンを追加する方法です

 cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
 UIImage *image = [UIImage imageNamed:@"Gear"];
 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
 CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
 button.frame = frame;
 [button setBackgroundImage:image forState:UIControlStateNormal];
 button.backgroundColor = [UIColor clearColor];
 [button addTarget:self action:@selector(customButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];
 cell.accessoryView = button;
4

1 に答える 1

3

の呼び出しは、がの場合にindexPathForRowAtPoint:戻ることができます。nilself.tableViewnil

設定されていることを確認してくださいself.tableView(たとえば、IBOutletの場合は、xibのテーブルビューに接続されていることを確認してください)。

于 2013-01-25T16:49:18.593 に答える