gpt4 book ai didi

ios - 为什么 tableView 的 FooterView 在 vi​​ewDidLoad() 中不存在,如何解决?

转载 作者:行者123 更新时间:2023-11-28 14:15:33 26 4
gpt4 key购买 nike

我有 tableView,在 Storyboard中设置了一个部分和页脚。我正在尝试使用以下代码更改 viewDidLoad() 中表格的 footerView 中的文本

tableView.footerView(forSection: 0)?.textLabel?.text = "Testing text"

但是 tableView.footerView(forSection: 0) == nil

然后在用户点击按钮时,我使用相同的代码调用更改 footerView 文本的函数,它完美地工作。

func changeFooterText() {
tableView.footerView(forSection: 0)?.textLabel?.text = "Testing text after tap"
}

为什么 viewDidLoad 中不存在 footerView?如何在 viewDidLoad 中更改它的文本?还是我应该在其他地方更改它?加载屏幕后,我需要在页脚中显示取决于屏幕上其他数据的文本。

期待阅读您的建议。

最佳答案

您可以使用表脚 View 方法:

override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? 

关于ios - 为什么 tableView 的 FooterView 在 vi​​ewDidLoad() 中不存在,如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52210206/

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