我正在尝试按照 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)
{
}
}
问题是索引路径始终为零。每次都无懈可击。有没有其他人遇到过这个?
编辑 这就是我添加按钮的方式
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;