Ios 修改swift中操作的表格单元格标题

Ios 修改swift中操作的表格单元格标题,ios,swift,uitableview,tableview,Ios,Swift,Uitableview,Tableview,在我的分区表格视图中有一个标题,其中包含一个按钮,点击该按钮时会展开单元格,标题中也有一个向右的箭头,当点击标题时,我想将该箭头图像更改为向下的箭头,如何更改该节的标题?特别是箭头按钮 func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { let header = UIView(frame: CGRect(x: 0, y: 0,

在我的分区表格视图中有一个标题,其中包含一个按钮,点击该按钮时会展开单元格,标题中也有一个向右的箭头,当点击标题时,我想将该箭头图像更改为向下的箭头,如何更改该节的标题?特别是
箭头按钮

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        
        let header = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 50))
        
        let button = UIButton(frame: CGRect(x: 0, y: 0, width: tableView.frame.width - 30, height: 50))
        button.setTitle(tableDataSource[section][0].mod.modType!, for: .normal)
        button.titleLabel?.font = UIFont(name: "Helvetica neue", size: 20)
        button.addTarget(self, action: #selector(headerPressed(sender:)), for: .touchUpInside)
        button.titleLabel?.textAlignment = .left
        
        button.tag = section
        
        let arrowButton = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
        arrowButton.setImage(UIImage(systemName: "chevron.right", compatibleWith: nil), for: .normal)
        header.addSubview(arrowButton)
        
        header.addSubview(button)
        header.backgroundColor = UIColor.green
        
        
        
        return header
    }

@objc func headerPressed(sender: UIButton){
        if(tableDataSource[sender.tag][0].clicked == false){
            tableDataSource[sender.tag][0].clicked = true
        } else {
            tableDataSource[sender.tag][0].clicked = false
        }
        let sections = IndexSet.init(integer: sender.tag)
        tableView.reloadSections(sections, with: .fade)
    }

您需要在
viewForHeaderInSection

let name = tableDataSource[section][0].clicked ? "chevron.right" : "chevron.left"
arrowButton.setImage(UIImage(systemName:name, compatibleWith: nil), for: .normal)

调用这个
tableView.reloadSections(带有:.fade的节)
将完成重新加载工作

,我正试图在
headerPressed
函数中完成它,谢谢!