objective-cxcodeuitableviewuitableviewrowactionuiswipeactionsconfiguration

UiSwipeActionsConfiguration - Cell reloads itself on first start


The strange behavior:

The Cell reloads its actions on first start, but trailingSwipeActionsConfigurationForRowAtIndexPath is only called once, any ideas?

The code:

- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {

UIContextualAction *deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:nil handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
    
   //...
    
}];

UIContextualAction *moreAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
    
    //...
    
    completionHandler(YES);
}];

deleteAction.backgroundColor = [UIColor colorWithRed:(245/255.0) green:(78/255.0) blue:(70/255.0) alpha:1];
moreAction.backgroundColor = [UIColor colorNamed:@"CL_LightGray_2"];

UISwipeActionsConfiguration *swipeActions = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction,moreAction]];
swipeActions.performsFirstActionWithFullSwipe=false;
return swipeActions;

}


Solution

  • I found the problem! For all those who have the same problem in the future:

        [UIView animateWithDuration:1.0 animations:^{
    
        //...
    
      }];
    

    As soon as this code is executed elsewhere, the cell's actions are also reloaded .This creates the strange behavior.