Swift 选择多个部分中的所有TableView行

Swift 选择多个部分中的所有TableView行,swift,swift4.2,Swift,Swift4.2,我在tableview中有一个按钮,当我按下该按钮时,将选择所有单元格行,如何操作? 我已经准备好了一个代码,我试着做这个函数。请帮帮我 我有一个数组: var days: [String] = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] tableView.dequeueReusableCell(withIdentifier: "selectall", for: indexPa

我在tableview中有一个按钮,当我按下该按钮时,将选择所有单元格行,如何操作? 我已经准备好了一个代码,我试着做这个函数。请帮帮我

我有一个数组:

var days: [String] = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]


tableView.dequeueReusableCell(withIdentifier: "selectall", for: indexPath) as! SelectAllTableViewCell

        cell.selectallBtn.addTarget(self, action: #selector(checkAllSelection(_:)), for: .touchUpInside)
        return cell
    } else if indexPath.section == 1 {
        let cell = tableView.dequeueReusableCell(withIdentifier: "oprearateCell", for: indexPath) as UITableViewCell
        return cell
    } else if indexPath.section == 2 {
        let cell = tableView.dequeueReusableCell(withIdentifier: "daycell", for: indexPath) as UITableViewCell as! DaysTableViewCell
        cell.dayLabel.text = self.days[indexPath.row]
        if selectedRows.contains(indexPath)
        {
            cell.checkmark.image = UIImage(named:"checkBoxMaterial")
        }
        else
        {
            cell.checkmark.image = UIImage(named:"checkBoxOutlineBlankMaterial")

        }
        cell.checkButton.addTarget(self, action: #selector(checkBoxSelection(_:)), for: .touchUpInside)
        cell.checkButton.tag = indexPath.row
        return cell
    }}
这里是我的多选代码

@objc func checkBoxSelection(_ sender:UIButton)
{
    let selectedIndexPath = IndexPath(row: sender.tag, section: 2)
    if self.selectedRows.contains(selectedIndexPath)
    {
        self.selectedRows.remove(at: self.selectedRows.index(of: selectedIndexPath)!)
        print(self.days[selectedIndexPath.row])
        let getDays = self.days[selectedIndexPath.row]
        operationDays.remove(object: getDays)
        print("remove",operationDays)
    }
    else
    {
        self.selectedRows.append(selectedIndexPath)
        operationDays.append(self.days[selectedIndexPath.row])
        print(operationDays)
    }
    self.tableView.reloadData()}
这里是我的全选代码

@objc func checkAllSelection(_ sender:UIButton)
{
    let selectedIndexPath = IndexPath(row: sender.tag, section: 0)
    if self.selectedRows.contains(selectedIndexPath)
    {
        selectAll = false
        self.selectedRows.remove(at: self.selectedRows.index(of: selectedIndexPath)!)
    }
    else
    {
        selectAll = true
        self.selectedRows.append(selectedIndexPath)
    }
    self.tableView.reloadData()
}
当你按下按钮,它将是真的

但我不知道该把这个放在哪个函数里?我不知道如何选择所有行