Objective C - UICollectionViewListCell Add swipe to delete

169 views Asked by At

Trying to implement "Swipe to Delete" API for UICollectionViewListCell.

I'm writing in Objective-C the compiler is not auto-completing the code. Any reasons? example code?

Swift example:

  let listConfig = UICollectionLayoutListConfiguration(appearance: .insetGrouped)

listConfig.trailingSwipeActionsConfigurationProvider = { [weak self] indexPath in 
  guard let self = self else { return nil }
    
  let action = UIContextualAction(style: .normal, title: "Done!", handler: actionHandler)
  return UISwipeActionsConfiguration(actions: [action])

}

Any code example for Objective C?

trying to reach the following result:

enter image description here

1

There are 1 answers

0
Ofir Malachi On
UICollectionLayoutListConfiguration * listConfiguration = [[UICollectionLayoutListConfiguration alloc]initWithAppearance:UICollectionLayoutListAppearanceInsetGrouped];
    [listConfiguration setTrailingSwipeActionsConfigurationProvider:^UISwipeActionsConfiguration* (NSIndexPath *indexPath) {
        
        UIContextualAction *action = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:[NSLocalizedString(@"Delete", nil)capitalizedString] handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {

        }];
        
        return [UISwipeActionsConfiguration configurationWithActions:@[action]];
    }];