Right swipe option in IOS swift

Solution:

You guys know that left swipe option to delete and other actions in iOS.You can use editactionforRow method to achieve that.

Also right swipe option is available.To implement the below method.


    @available(iOS 11.0, *)
    func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
            
            let swipeConfig = UISwipeActionsConfiguration(actions: [self.contextualToggleReadAction(forRowAtIndexPath: indexPath)])
            return swipeConfig
    }





    // MARK: - Right swipe
    
    @available(iOS 11.0, *)
    func contextualToggleReadAction(forRowAtIndexPath indexPath: IndexPath) -> UIContextualAction {
        let title = "Add"
        let action = UIContextualAction(style: .normal, title: title) { (contextAction: UIContextualAction, sourceView: UIView, completionHandler: (Bool) -> Void) in
                self.TableView.reloadRows(at: [IndexPath(row: indexPath.row, section: 0)], with: .none)
            }
            
        }
        action.backgroundColor = UIColor().swipeGreen()
        action.image = UIImage(named: "img")
        return action
    }

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift