UIButton touchUpInside与UITableViewCell滑动事件冲突

时间:2016-07-14 06:34:28

标签: ios objective-c uitableview uibutton

我在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事件都会被触发 我该怎么控制呢?

1 个答案:

答案 0 :(得分:5)

您可以通过查看isEditing UITableViewbutton的{​​{1}}属性来解决您的问题

action
相关问题