Right swipe in iOS swift like email app

Solution:

Before iOS 11 no methods for right swipe.So you can handle it by using swipe gesture with right swipe.And handle in a method.like below for a table View cell

    var swipeRight = UISwipeGestureRecognizer(target: self, action: "rightSwipeGesture:")
    swipeRight.direction = UISwipeGestureRecognizerDirection.Right
    cell.addGestureRecognizer(swipeRight)

The method will be like below
func rightSwipeGesture(gesture: UIGestureRecognizer) {

}


But in iOS 11 below method used for right swipe

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
        let swipeAction = self.contextualDeleteAction(forRowAtIndexPath: indexPath)
        let swipeConfig = UISwipeActionsConfiguration(actions: [swipeAction ])
        return swipeConfig
    }


If you want the above method not wants to be work at some condition then you can return nil.It will works.

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
if (your condition)
        return swipeConfig
    }







Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

store cgpoint in userdefaults iOS swift