在建立 UITableView
的時候,在沒有 cell 的地方還是會有等距的分隔線跑出來,這篇文章將說怎麼移除這些分隔線。
iOS 6.1 及 iOS 7.*
最簡單的方式就是設定 tableView 的 tableFooterView
property 的矩形大小設定為 0 :
1
2
3
4
5
6
7
| - (void)viewDidLoad
{
[super viewDidLoad];
// 這一行就會讓分隔線消失
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}
|
比較舊的版本
用 UITableViewDelegate
的 method 直接指定一個很小的高度給 footer view 就可以了:
1
2
3
4
| - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.01f;
}
|
如果覺得這個方法還不夠,也可以直接再加上一個 delegate method ,回傳一個新的 UIView
:
1
2
3
4
| - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
return [UIView new];
}
|
如果是 non-ARC ,請加上 autorelease
:
1
2
3
4
| - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
return [[UIView new] autorelease];
}
|