Ios 检测UIControlEventTouchUpInside并删除UITableViewCell手势
在UITableViewCell内的UIButton内检测UIControlEventTouchUpInside时出现问题。应用程序实现UITableView类的edit delegate方法,以允许用户删除单元格 当我点击按钮时,它会触发选择器并执行它必须执行的操作(正确的行为)。问题是当我做删除按钮相同位置开始的单元格的手势时。编辑代理方法和指定给按钮的选择器都会被触发。因此,该行为不是预期的,因为单元格被移动,按钮逻辑也被执行。有没有办法检测用户是否做了删除手势,但没有点击手势 这是我的实现,希望这会有所帮助 编辑委托方法的实现:Ios 检测UIControlEventTouchUpInside并删除UITableViewCell手势,ios,uitableview,Ios,Uitableview,在UITableViewCell内的UIButton内检测UIControlEventTouchUpInside时出现问题。应用程序实现UITableView类的edit delegate方法,以允许用户删除单元格 当我点击按钮时,它会触发选择器并执行它必须执行的操作(正确的行为)。问题是当我做删除按钮相同位置开始的单元格的手势时。编辑代理方法和指定给按钮的选择器都会被触发。因此,该行为不是预期的,因为单元格被移动,按钮逻辑也被执行。有没有办法检测用户是否做了删除手势,但没有点击手势 这是我的实
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
...
}
}
以下是UIButton实现:
UIButton *videoButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
videoButton.backgroundColor = [UIColor clearColor];
[videoButton addTarget:self action:@selector(videoButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:videoButton];
- (void)videoButtonTapped:(id)sender
{
(some domain logic...)
}
以及选择器方法实现:
UIButton *videoButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
videoButton.backgroundColor = [UIColor clearColor];
[videoButton addTarget:self action:@selector(videoButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:videoButton];
- (void)videoButtonTapped:(id)sender
{
(some domain logic...)
}
尝试将
UIControlEventTouchDragInside
事件添加到videoButton,以便您可以检查用户是否拖动或刚刚点击。每次开始编辑单元格(滑动)时,单元格将其编辑状态更改为“是”,以便您可以在videoButtonTapped:方法上检查单元格的编辑模式,所以,若单元格处于编辑模式,则什么也不做