UITableView 删除编辑样式仅在管理员登录后可用

UITableView Delete Editing Style only available when admin is logged in

如何让UItableView删除编辑样式只在登录用户为admin时可用?当其他用户登录或没有用户登录时,向左滑动该行时会出现删除选项,虽然只有当登录用户是管理员时才会执行删除操作,但我不希望它向左滑动该行时出现。请帮忙。

    func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {

        if MUser.currentUser() != nil {
            if MUser.currentUser()!.email == kADMIN {

                if editingStyle == .delete {

                    let voucherToDelete = voucherArray[indexPath.row]

                    voucherArray.remove(at: indexPath.row)
                    tableView.reloadData()

                    print("This is the voucherToDelete \(voucherToDelete.id!)")

                    deleteVoucherFirestore(voucherToDelete.id!) { (error) in


                        if error != nil {
                            print("error udpating the voucher", error!.localizedDescription)
                        }
                        self.loadItems()
                    }

                }

            }
        }

    }

在您的代码中实现此功能

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    guard let user = MUser.currentUser(), user.email == kADMIN else { return false }
    return true
}