Ios 为什么UITableView页脚显示在最后一个单元格的顶部?

Ios 为什么UITableView页脚显示在最后一个单元格的顶部?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有一个UITableView,其中包含一组单元格(动态生成),并显示一条页脚消息,显示上次更新的时间。我遇到的问题是,在第一次加载UITableView时,页脚似乎显示在最后一个单元格的顶部。重新加载数据后,它会正确显示数据 有人知道为什么会这样吗 初始加载: 重新加载后: 以下是我用于建立要显示的页脚消息的逻辑: override func tableView(tableView: UITableView, titleForFooterInSection section: Int) -&

我有一个
UITableView
,其中包含一组单元格(动态生成),并显示一条页脚消息,显示上次更新的时间。我遇到的问题是,在第一次加载
UITableView
时,页脚似乎显示在最后一个单元格的顶部。重新加载数据后,它会正确显示数据

有人知道为什么会这样吗

初始加载:

重新加载后:

以下是我用于建立要显示的页脚消息的逻辑:

override func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? {

    var title = ""
    if (section == kSectionA) {
        if (!self.hasInternet) {
            title = "No Internet Connection"
        } else {
            if (self.dataToDisplay) {
                title = "Last Updated: xx:xx AM"
            } else {
                title = "No results found."
            }
        }
    }

    return title
}

您需要从一开始就告诉Tableview页脚有多大。请尝试使用此代码,但使用您的值

告诉Tableview页脚有多大:

override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let footerView = UIView(frame: CGRectMake(0, 0, tableView.frame.size.width, 40))
footerView.backgroundColor = UIColor.grayColor()

return footerView
}
override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 40.0
}
告诉页脚页脚有多大:

override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let footerView = UIView(frame: CGRectMake(0, 0, tableView.frame.size.width, 40))
footerView.backgroundColor = UIColor.grayColor()

return footerView
}
override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 40.0
}

这应该能解决你的问题

因为您未能告诉视图控制器单元格的高度。能否提供以下内容:func tableView(tableView:UITableView,heightForRowAtIndexPath:nsindepath)->CGFloat{我认为您需要在该函数中增加行的高度。也可以通过以下方法解决此问题。可能该代码解决了与此问题相关的大部分问题,但我发现他使用的是TitleForFooterInstition,而不是ViewForFooterInstition。但用户应该响应。