Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - disable right or left swipe for UITableViewCell

I have implemented iOS 11 trailingSwipeActionsConfigurationForRowAt and leadingSwipeActionsConfigurationForRowAt for my UITableViewCell. I'm using trailingSwipeActionsConfigurationForRowAt to disable the row, and leadingSwipeActionsConfigurationForRowAt to undo the disable of the row. I've tried to use canEditRowAt, but this disables editing of the entire row. Is there a way to disable only one of the swipe actions instead of disabling the entire row from editing?

I want to disable the undo swipe action if I already swiped to undo, but enable the cancel swipe action. I also want to disable the cancel swipe action if I already swiped to cancel, but enable the undo swipe action.

like image 605
Andrew P. Avatar asked May 29 '18 23:05

Andrew P.


1 Answers

Try to return the empty array of actions in trailingSwipeActionsConfigurationForRowAt method to disable one sided action.

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

   let swipeAction = UISwipeActionsConfiguration(actions: [])

   return swipeAction
}
like image 55
pkc456 Avatar answered Oct 24 '22 08:10

pkc456