简体   繁体   English

UIButton touchUpInside与UITableViewCell滑动事件冲突

[英]UIButton touchUpInside conflicts with UITableViewCell swipe event

I am displaying swipe button in UITableViewCell as follows : 我在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 {

}  

In the cell's contentView , I have placed a UIButton which has a UIControlEventTouchUpInside controlEvent . 在单元格的contentView ,我放置了一个UIButton ,该controlEvent具有UIControlEventTouchUpInside controlEvent
When I swipe the cell by touching the button area, both the swipe and UIButton event are fired. 当我通过触摸按钮区域来滑动单元格时,将同时触发swipe和UIButton事件。
How can I control this ? 我该如何控制?

You can solved your problem by checking isEditing property of UITableView in your button action like this 您可以通过在这样的button action检查UITableView isEditing属性来解决您的问题

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM