I am displaying swipe button in UITableViewCell
as follows :
- (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
.
When I swipe the cell by touching the button area, both the swipe and UIButton
event are fired.
How can I control this ?
You can solved your problem by checking isEditing
property of UITableView
in your button
action
like this
- (void)btnTap:(UIButton*) sender {
if (!self.tableActivities.isEditing) {
//Perform Action
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.