-1

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

Ofir Malachi
  • 1,145
  • 14
  • 20
  • 1
    No tested, but I guess that something like that https://pastebin.com/X5SYwEVK might do the trick. I didn't do the `[weak self]` because you don't use `self` inside the closure, but to do so, read about `weak self` in Objective-C if you need it. – Larme Jan 23 '23 at 15:20
  • This is a repost of your previous question: [Objective C - UICollectionViewListCell swipe to delete](https://stackoverflow.com/questions/75200737/objective-c-uicollectionviewlistcell-swipe-to-delete). Instead of reposting you should edit the original as needed. – HangarRash Jan 23 '23 at 18:14

1 Answers1

0
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]];
    }];
Ofir Malachi
  • 1,145
  • 14
  • 20