iOS8中 UITableView section 分区头部视图不显示

来源:互联网 发布:北京市网络宣传管理处 编辑:程序博客网 时间:2024/05/19 22:02

最近自己使用了UITableView写了一个通讯录,但是在编写过程还算顺利,但是后来测试的时候,发现在iOS8中TableView的分区头不能正常显示,使用

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section  

方法可以正常的设置分区的Title,但是如果你使用了

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;

设置了分区的sectionHeaderView,那么你会发现在iOS8之前的系统中可以正常的现实分区的头部视图,而从iOS8开始只设置此方法是无法显示头部视图的,所以你需要在配合着下面方法,为TableView设置分区视图的高度

<span style="font-size:18px;">- (CGFloat)tableView:(UITableView * )tableView heightForHeaderInSection:(NSInteger)section;</span>


另外,如果代码中设置了titleForHeaderInSection,则不需要上面的设置也可以正常显示。










ios8 如果UITableView只设置viewForHeaderInSection,则可能section不能显示,iOS7及以下版本显示正常。 解决方案: 设置heightForHeaderInSection。 - (CGFloat)tableView:(UITableView * )tableView heightForHeaderInSect

0 0