簡體   English   中英

如何在 Swift 中訪問 TableView 標題中的按鈕?

[英]How to to access button in TableView header in Swift?

我目前無法訪問 tableView 標題部分中的按鈕。 我的按鈕位於我的表格視圖的第一個標題部分(其中包含兩個標題,我想要訪問的按鈕僅在第一個標題中)。 這是我當前文件的示例。 基本上,我想做的是嘗試訪問第一個標題中的按鈕。

表視圖文件

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    guard let vM = suggestionSections[safeIndex: section] else { return nil }
    let header = SectionHeaderView(frame: .zero)
    header.configure(vM)
    header.delegate = delegate
    return header
}

SectionHeaderView 文件

private var button = UIButton()
lazy var button = UIButton() //private remove

然后查看部分中的標題

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    guard let vM = suggestionSections[safeIndex: section] else { return nil }
    let header = SectionHeaderView(frame: .zero)
    header.configure(vM)
    if section == 0 {
        header.button.backgroundColor = .red
    } else {
    //hide or do something with button
    }
    header.delegate = delegate
    return header
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM