Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Row deletions - extra argument in call: rowActions #196

Closed
csr opened this issue May 15, 2020 · 1 comment
Closed

Row deletions - extra argument in call: rowActions #196

csr opened this issue May 15, 2020 · 1 comment

Comments

@csr
Copy link

csr commented May 15, 2020

Hi, I previously used to delete rows by specifying a UITableViewRowAction in rowActions property like so

let deleteRowAction = UITableViewRowAction(style: .destructive, title: "Delete", handler: ({ (rowAction, indexPath) in
    self.didTapDeleteOnRow(indexPath: indexPath)
}))

let rows: [CellConfigType] = getSourceArray().enumerated().map { index, item in
    return HistoryCell(
        key: "index-\(index)-\(item.translatedText)",
        style: cellStyle,
        actions: CellActions(
            selectionAction: { _ in
                self.didSelectCell(translation: item)
                return .selected
        },
            deselectionAction: { _ in
                return .deselected
        }, rowActions: [deleteRowAction]),   // <---- here
        state: HistoryState(translationItem: item),
        cellUpdater: HistoryState.updateView)
}

Now I see rowActions isn't part of the initializer anymore, so I'm wondering how to enable cell deletion. Any insights?

@csr csr changed the title Delete row Row deletions - extra argument in call: rowActions May 15, 2020
@g-Off
Copy link
Contributor

g-Off commented May 15, 2020

Hi @csr, thanks for reaching out.
We've moved to a slightly different model here to better take advantage of the APIs exposed in iOS 11+, specifically the UISwipeActionsConfiguration. This allows images and full row swipe as well as having both leading and trailing actions.

I've tweaked your example a bit to show how the new version would work. One note is that I had to change the call to self.didTapDeleteOnRow to self.didTapDeleteOnItem since an IndexPath isn't available anymore.

let rows: [CellConfigType] = getSourceArray().enumerated().map { index, item in
    let deleteAction = CellActions.SwipeActionsConfiguration.ContextualAction(title: "Delete", backgroundColor: UIColor.red, style: .destructive) { _, completion in
        self.didTapDeleteOnItem(item)
        completion(true) // The true signifies a successful deletion
    }
    return HistoryCell(
        key: "index-\(index)-\(item.translatedText)",
        style: cellStyle,
        actions: CellActions(
            selectionAction: { _ in
                self.didSelectCell(translation: item)
                return .selected
        },
            deselectionAction: { _ in
                return .deselected
        },
			trailingActionConfiguration: CellActions.SwipeActionsConfiguration(actions: [deleteAction]) // <---- here
		),
        state: HistoryState(translationItem: item),
        cellUpdater: HistoryState.updateView)
}

@csr csr closed this as completed May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants