我希望用户在单击表格单元格而不是行中的附件图像时获得不同的结果。
为了捕获他们对配件的点击,我使用以下方法:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;{
NSLog(@"accessory button tapped");
}
此外,我没有使用标准指标。相反,我使用自定义图像,如下所示:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
[cell setAccessoryView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"checkmark.png"]]];
}
覆盖标准附件按钮并显示图像。注意:无论 Storyboard中的公开指示器设置为“无”、复选标记、公开指示器等,它都会显示图像。
但是,目前
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;{
NSLog(@"accessory button tapped");
}
方法未触发。
有一些answers SO 表明,如果附件是附件 View 而不是附件类型,则不会调用此方法。
有谁知道是否可以使用自定义图像并且仍然可以通过点击按钮的方法来触发?
最佳答案
您可以通过以下方式在 UIImageView 上添加标签手势
UIImageView *imgView= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"checkmark.png"]];
imgView.tag = indexPath.row;
UITapGestureRecognizer *tapGesture1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)];
tapGesture1.numberOfTapsRequired = 1;
[tapGesture1 setDelegate:self];
[imgView addGestureRecognizer:tapGesture1];
[cell setAccessoryView:];
并添加选择器方法
- (void) tapGesture: (id)sender
{
//handle Tap...
}
希望对你有帮助
关于ios - 区分accessoryView和Row on touch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32991284/