将我的代码库从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方法
发布评论