43

我正在处理UITableView我的项目,这个项目是在 Xcode 4.5 中创建的,现在我正在使用 Xcode 5,所以我的问题是什么时候我将在 iOS 6 中运行我的项目,viewForHeaderInSection方法部分从 0 开始没关系,但如果我将使用 iOS 7 运行viewForHeaderInSection部分从 1 开始而不是从 0

有什么问题 有没有UITableView框架的问题

我不明白发生了什么

提前致谢

4

2 回答 2

101

刚刚遇到完全相同的问题,解决方案非常简单。

只需实现这个委托方法:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 20;
}

Form Apple UITableViewDelegate Protocol Reference,它提到

讨论

返回的对象可以是 UILabel 或 UIImageView 对象,也可以是自定义视图。此方法仅在同时实现 tableView:heightForHeaderInSection: 时才能正常工作。

于 2013-09-21T16:30:18.410 回答
8

斯威夫特 3 版本:

override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 60
}
于 2016-10-18T09:38:13.950 回答