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

标签 ios swift uitableview tablefooterview

我有 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/

相关文章:

ios - UICollectionView 必须在 Swift 中使用非 nil 布局参数进行初始化,即使该参数是在 UICollectionView 文件中定义的

ios - 为什么我的 Cordova 应用程序创建了这么多 iframe?

ios - 如何在ios中获取一个部分的行数

string - 如何在 swift 3.0 中连接多个可选字符串?

swift - 避免 Swift 中函数指针的保留循环

ios - 无效更新: invalid number of rows in section 0 when trying to expand and collapse UITableView sections

ios - 在 Swift 的 UITextfield 中滚动 Tableview 数据重新洗牌

ios - 为什么我的 UILabel 框架代码在 iOS 6 中有效,但在 iOS 7 中无效?

ios - Apple inapp Non-Renewing 订阅购买,强制要求登录?

iphone - 通过目的地的 Google map KML 输出或带有 MKMapkit 的 Google Direction API