在Swift 3.0和Xcode 8迁移后未调用UITableViewDelegate方法 [英] UITableViewDelegate methods not called after Swift 3.0 and Xcode 8 migration

查看:141
本文介绍了在Swift 3.0和Xcode 8迁移后未调用UITableViewDelegate方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将我的代码库从Swift 2.2迁移到Swift 3.0之后,我注意到我的 UITableView 页脚没有显示出来。事实证明,我的 UITableViewDelegate 方法都没有被调用(例如: func tableView(_ tableView:UITableView,viewForFooterInSection section:Int) - > UIView ?)。

After migrating my codebase from Swift 2.2 to Swift 3.0, I noticed that my UITableView footer did not show up. It turns out that none of my UITableViewDelegate methods get called (ex: func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView?).

有趣的是,正在调用 UITableViewDataSource 方法并填充。我已将父视图控制器设置为表的委托 dataSource

Interestingly, the UITableViewDataSource methods are being called and the table is being populated. I have set the parent view controller to be the table's delegate and dataSource.

为了说明这个问题,我创建了一个示例Swift 3.0项目。尽可能匹配我现有的代码库。也许Swift 3 / Xcode 8中有些东西发生了变化,我不知道或者我可能会遗漏一些非常明显的东西。谢谢你的帮助!

To illustrate the problem, I have created a sample Swift 3.0 project tailored to match my existing codebase as much as possible. Maybe something changed in Swift 3/Xcode 8 that I am not aware of or I might be missing something really obvious. Thank you for your help!

推荐答案

检查完你的示例项目之后:

After I checked your sample project:

你没有做错任何事,但是参考 viewForFooterInSection ,在你实现 heightForFooterInSection 方法:

You didn't did anything wrong, but referring to viewForFooterInSection, it will not get called until you implement heightForFooterInSection method:

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return 50 // for example
}

类似案例:

没有实现 heightForHeaderInSection ==>不要求 viewForHeaderInSection 即使它已实现。

No implementing for heightForHeaderInSection ==> No calling for viewForHeaderInSection even if it's implemented.

返回 numberOfRowsInSection 为零==>没有调用对于 cellForRowAt 即使它已实施。

Returning numberOfRowsInSection as zero ==> No calling for cellForRowAt even if it's implemented.

附加说明:你没有在 viewDidLoad()<中添加 tableView.dataSource = self tableView.delegate = self / code>,它们已在界面生成器中设置。

Additional Note: you don't have to add tableView.dataSource = self and tableView.delegate = self in viewDidLoad(), they have been set in the interface Builder.

这篇关于在Swift 3.0和Xcode 8迁移后未调用UITableViewDelegate方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆