不顯示 UITableView 中空 Cells 分隔線
在建立 UITableView
的時候,在沒有 cell 的地方還是會有等距的分隔線跑出來,這篇文章將說怎麼移除這些分隔線。
iOS 6.1 及 iOS 7.*
最簡單的方式就是設定 tableView 的 tableFooterView
property 的矩形大小設定為 0 :
1 | - (void)viewDidLoad |
比較舊的版本
用 UITableViewDelegate
的 method 直接指定一個很小的高度給 footer view 就可以了:
1 | - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section |
如果覺得這個方法還不夠,也可以直接再加上一個 delegate method ,回傳一個新的 UIView
:
1 | - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section |
如果是 non-ARC ,請加上 autorelease
:
1 | - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section |