tableView编辑样式设计

来源:互联网 发布:双十一卫浴网络销售额 编辑:程序博客网 时间:2024/05/18 03:16
    override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {        let actionShare = UITableViewRowAction(style: .default, title: "分享") { (_, indexPath) in            let alert = UIAlertController(title: "分享到", message: nil, preferredStyle: .actionSheet)            let qq = UIAlertAction(title: "QQ", style: .default, handler: nil)            let weixin = UIAlertAction(title: "微信", style: .default, handler: nil)            let cancel = UIAlertAction(title: "取消", style: .cancel, handler: nil)            alert.addAction(qq)            alert.addAction(weixin)            alert.addAction(cancel)            self.present(alert, animated: true, completion: nil)        }        actionShare.backgroundColor = UIColor.orange        let actionTop = UITableViewRowAction(style: .default, title: "置顶") { (_, indexPath) in            self.exchange(indexPath, to: IndexPath(row: 0, section: 0))            tableView.moveRow(at: indexPath, to: IndexPath(row: 0, section: 0))            DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3, execute: { // 延迟处理                tableView.setEditing(false, animated: true)            })        }        let actionDele = UITableViewRowAction(style: .destructive, title: "删除"){ (_, indexPath) in            self.removeMode(indexPath)            tableView.deleteRows(at: [indexPath], with: .fade)            print("还剩余数量:",self.ares.count)            for area in self.ares {                print(area)            }        }        actionTop.backgroundColor = UIColor(red: 245/255, green: 199/255, blue: 244/255, alpha: 1)        return [actionDele, actionShare, actionTop]    }

一旦实现了上述方法,则下面的方法就不会调用

    override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {        if editingStyle == .delete {            // Delete the row from the data source            self.removeMode(indexPath)            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        }        }
0 0
原创粉丝点击