【问题标题】:UIButton touchUpInside conflicts with UITableViewCell swipe eventUIButton touchUpInside 与 UITableViewCell 滑动事件冲突
【发布时间】:2016-07-14 06:34:28
【问题描述】:

我在UITableViewCell 中显示滑动按钮如下:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (nullable NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewRowAction *cancelAction;
    UITableViewRowAction *editAction;
    UITableViewRowAction *messageAction;
     cancelAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Cancel" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
        [tableActivities setEditing:NO];
    }];
    cancelAction.backgroundColor = [UIColor blueColor];

    editAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Edit" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
        [tableActivities setEditing:NO];
    }];
    editAction.backgroundColor = [UIColor greenColor];

    messageAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Message"  handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
        [tableActivities deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    }];

    return @[messageAction, cancelAction, editAction];
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

}  

在单元格的contentView 中,我放置了一个UIButton,它有一个UIControlEventTouchUpInside controlEvent
当我通过触摸按钮区域滑动单元格时,会触发滑动和UIButton 事件。
我该如何控制?

【问题讨论】:

  • UITableView.canCancelContentTouches 我认为应该防止这种情况发生。
  • @Andy : 卷轴不能用吗?

标签: ios objective-c uitableview uibutton


【解决方案1】:

您可以通过在您的button action 中检查UITableViewisEditing 属性来解决您的问题

- (void)btnTap:(UIButton*) sender {
    if (!self.tableActivities.isEditing) {
        //Perform Action
    }
}

【讨论】:

  • 欢迎快乐编码:)
猜你喜欢
  • 2019-12-04
  • 1970-01-01
  • 1970-01-01
  • 2018-08-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多