美文网首页Swift基础入坑
自定义cell滑动菜单

自定义cell滑动菜单

作者: iOS_July | 来源:发表于2018-06-11 10:39 被阅读16次
使用该方法后,系统的删除就不管用了
override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
系统删除
 override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
        if editingStyle == .delete {
            // Delete the row from the data source
            areas.remove(at: indexPath.row)
            provinces.remove(at: indexPath.row)
            parts.remove(at: indexPath.row)
            areaImages.remove(at: indexPath.row)
            visited.remove(at: indexPath.row)
            
            tableView.deleteRows(at: [indexPath], with: .fade)
        } else if editingStyle == .insert {
            // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
        }    
    }

自定义的滑动菜单

override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
        
        let actionShare = UITableViewRowAction(style: .normal, title: "分享") { (_, indexPath) in
            let alertSheet = UIAlertController(title: "分享到", message: nil, preferredStyle: .actionSheet)
            
            let option1 = UIAlertAction(title: "QQ", style: .default, handler: nil)
            let option2 = UIAlertAction(title: "微信", style: .default, handler: nil)
            let option3 = UIAlertAction(title: "微博", style: .default, handler: nil)
            let option4 = UIAlertAction(title: "算了吧", style: .cancel, handler: nil)
            
            alertSheet.addAction(option1)
            alertSheet.addAction(option2)
            alertSheet.addAction(option3)
            alertSheet.addAction(option4)
            
            self.present(alertSheet, animated: true, completion: nil)
        }
        let actionDelete = UITableViewRowAction(style: .destructive, title: "删除") { (_, indexPath) in
            self.areas.remove(at: indexPath.row)
            self.provinces.remove(at: indexPath.row)
            self.parts.remove(at: indexPath.row)
            self.areaImages.remove(at: indexPath.row)
            self.visited.remove(at: indexPath.row)
            
            tableView.deleteRows(at: [indexPath], with: .fade)
        }
        let actionTop = UITableViewRowAction(style: .default, title: "我是紫色") { (_, indexPath) in
        }
        
        
        actionShare.backgroundColor = UIColor.orange
        actionTop.backgroundColor = UIColor.purple
        return [actionShare,actionDelete,actionTop]
    }

相关文章

网友评论

    本文标题:自定义cell滑动菜单

    本文链接:https://www.haomeiwen.com/subject/scyrsftx.html