如何调用按钮在TableView头节在其他文件和/或函数在Swift?



我一直在想办法把我的按钮所在的TableView section发送到另一个文件,我的动作处理程序所在的文件。我的按钮在tableview的第一个header section中。更具体地说,我不确定如何存储部分并将其发送到其他文件,在那里我可以使用它来触发我的SectionHeaderView中的按钮的某些动作。我需要创建一个函数/委托,并在部分传递和听到吗?下面是我使用的文件:

视图文件

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
if section == 0 { // where my button is located (i have two headers)
// want to send the section to SectionHeaderView file where I have my action func for when the button is tapped...
// ... or to other files where I have delegates
}
return header
}

SectionHeaderView文件
lazy var button = UIButton()

你可以给SectionHeaderView&赋值,财产在你viewForHeaderInSection:

var section: Int? // in SectionHeaderView
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
header.section = section //here
if section == 0 { // where my button is located (i have two headers)
// want to send the section to SectionHeaderView file where I have my action func for when the button is tapped...
// ... or to other files where I have delegates
}
return header
}

相关内容

  • 没有找到相关文章

最新更新