gpt4 book ai didi

ios - 从代码访问 TableView 标题

转载 作者:行者123 更新时间:2023-11-30 11:38:10 24 4
gpt4 key购买 nike

我的 TableView 中有一个 TableView 标题,它使用带有段控件的自定义单元格。

我已在 Storyboard中添加了手势识别器:

@IBAction func swipeLeftTapped(_ sender: Any) {
}

我想向左滑动并将 Storyboard标题中段控件的选定段减少 1。我该怎么做。这是我尝试过的,但显然它不起作用。

let header = self.mainTableView.cellForRow(at: IndexPath(row: 0, section: 0)) as! HeaderTableViewCell

还有

let header2 = self.mainTableView.headerView(forSection: 0) as! HeaderTableViewCell

header.productSegmentControl.selectedSegmentIndex += 1

这是我的表格 View 标题代码

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let cell = tableView.dequeueReusableCell(withIdentifier: "HeaderCell") as! HeaderTableViewCell
cell.productSegmentControl.selectedSegmentIndex = productIdIndex
return cell
}

如何像访问普通单元格一样访问表格 View 标题?

最佳答案

为什么要使用单元格作为标题,只需使用普通 View 并向该 View 添加您想要的任何内容,然后就可以访问它的 subview 。

查看马丁的回答 here

关于ios - 从代码访问 TableView 标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49521707/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com