我在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
事件都会被触发
我该怎么控制呢?
答案 0 :(得分:5)
您可以通过查看isEditing
UITableView
中button
的{{1}}属性来解决您的问题
action