UITableView 在没有数据时候分割线问题

在iOS4.3中可以直接设置footer为nil,但是在5.0不行,因为UITableView会默认生成一个Footer。

(详见iOS Release Notes中的说明:Returning nil from the tableView:viewForHeaderInSection: method (or its footer equivalent) is no longer sufficient to hide a header. You must override tableView:heightForHeaderInSection: and return 0.0 to hide a header.)

plain类型的tableview当显示的数据很少时,下面的cell即使不显示数据也会有分割线,可以通过下面这个函数去掉多余的分割线。

 

原因:在TableView创建的时候,tableView会默认生成一个Footer。当没有给Footer赋值,或者返回一定的高度的时候,TableView就会存在分割线。

 

解决方法:

1.直接返回一个 趋近0(大于0)的高度,肉眼几乎不可见,则在没有数据时分割线消失。

 

2.设置tableView的TableFooterView = [[UIView alloc] init];

 

3.设置TableView的分割线类型为None;(当数据源为nil时,不为nil时,设置为SingleLine)

 

4.全局设置为None,自定义View给TableView的Cell 加分割线。

posted @ 2016-04-21 17:11  会飞的夜良  阅读(757)  评论(0编辑  收藏  举报