xcode 在 iOS 7 viewForHeaderInSection 部分从 1 开始而不是从 0

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18932476/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:51:54  来源:igfitidea点击:

in iOS 7 viewForHeaderInSection section is starting from 1 not from 0

iphoneiosxcodeuitableviewios7

提问by Bhavesh Lathigara

I am dealing with UITableViewin my project and this project is created in Xcode 4.5 and now I am working with Xcode 5, so my question is when I will run my project in iOS 6 , the viewForHeaderInSectionmethod section is starting from 0 it's ok but If I will use iOS 7 to run viewForHeaderInSectionsection is starting from 1 not from 0

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

What is the problem is there any UITableViewframe's problem or not

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

I can't understand what is going on

我不明白发生了什么

Thanks in Advance

提前致谢

回答by Evan Chu

Just encountered exactly the same issue, and the resolution turns out very simple.

刚刚遇到完全相同的问题,结果很简单。

Just implement this delegate method:

只需实现这个委托方法:

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

Form Apple UITableViewDelegate Protocol Reference, it mentioned

形成Apple UITableViewDelegate Protocol Reference,它提到

Discussion

The returned object can be a UILabel or UIImageView object, as well as a custom view. This method only works correctly when tableView:heightForHeaderInSection: is also implemented.

讨论

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

回答by Manuel Escrig

Swift 3 Version:

斯威夫特 3 版本:

override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 60
}