UITableViewRowAction vs UISwipeActionsConfiguration

前端 未结 2 534
暗喜
暗喜 2021-01-11 19:35

The two APIs seem to get the same result. In which case is it better to use one over the other?

override func tableView(_ tableView: UITableView, editActions         


        
2条回答
  •  离开以前
    2021-01-11 19:50

    Here is the code which is working for me

    internal func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    
       // let delete = UITableViewRowAction(style: .destructive, title: "Delete") { (action, indexPath) in
        let contextItem = UIContextualAction(style: .destructive, title: "") {  (contextualAction, view, boolValue) in
        // delete item at indexPath
           //if self.isfilterenabled == true {
             //   return
            //}
    
    
            if self.isfilterenabled == true {
                //entryFilter.filteredEntries[indexPath.row]
                self.entryFilter.filteredEntries.remove(at: indexPath.row)
            } else {
                self.data.remove(at: indexPath.row)
            }
    
            self.table.deleteRows(at: [indexPath], with: .fade)
            self.save()
        }
    
    
    
        //let share = UITableViewRowAction(style: .normal, title: "SavePDF") { (action, indexPath) in
            // share item at indexPath
        let contextItemSave = UIContextualAction(style: .normal, title: "") {  (contextualAction, view, boolValue) in
    
    
    
    
    
            let alert  = UIAlertController(title: "Done! ", message: "PDF has been saved " ,preferredStyle: .alert)
    
            let okAction = UIAlertAction(title: "OK ", style: .default, handler: nil)
            alert.addAction(okAction)
    
            alert.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
    
            // exclude some activity types from the list (optional)
            //activityViewController.excludedActivityTypes = [ UIActivityTypeAirDrop, UIActivityTypePostToFacebook ]
    
            // present the view controller
            self.present(alert, animated: true, completion: nil)
            // present(alert, animated : true, completion : nil )
    
        }
    
       // share.backgroundColor = UIColor.blue
    
        contextItemSave.image = UIImage(named:"PDF.jpg")
        contextItem.image = UIImage(named:"delete.jpg")
        let swipeActions = UISwipeActionsConfiguration(actions: [contextItem,contextItemSave])
    
        return swipeActions
        //return [delete, share]
    }`
    

提交回复
热议问题