如何去掉tableView多余的空白行分割线?
我们经常会遇到下面的问题,tableView表视图上面的内容不是很多,但是 tableView 却帮忙把 整个屏幕都用 空白行分割线占满了:
如下图:
代码如下:
01.
//
02.
// TableViewController.m
03.
// Test
04.
//
05.
// Created by on 15/1/25.
06.
// Copyright (c) 2015年 http://blog.csdn.net/yangbingbinga. All rights reserved.
07.
//
08.
09.
#
import
"TableViewController.h"
10.
11.
@interface
TableViewController ()
12.
13.
@end
14.
15.
@implementation
TableViewController
16.
17.
- (
void
)viewDidLoad {
18.
[
super
viewDidLoad];
19.
20.
}
21.
22.
#pragma mark - Table view data source
23.
24.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
25.
return
1
;
26.
}
27.
28.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
29.
return
3
;
30.
}
31.
32.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
33.
{
34.
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@
"cell"
forIndexPath:indexPath];
35.
return
cell;
36.
}
37.
38.
@end
方法1. 完全去掉所有的分割线,然后 在cell上自定义 一个 view高度为一个像素,来模拟真实的 分割线
2.方法二,如果不想自定义分割线的话,那就来一个粗暴的方法吧,增加一个 footerView即可解决问题代码如下:
01.
//
02.
// TableViewController.m
03.
// Test
04.
//
05.
// Created by on 15/1/25.
06.
// Copyright (c) 2015年 http://blog.csdn.net/yangbingbinga. All rights reserved.
07.
//
08.
09.
#
import
"TableViewController.h"
10.
11.
@interface
TableViewController ()
12.
13.
@end
14.
15.
@implementation
TableViewController
16.
17.
- (
void
)viewDidLoad {
18.
[
super
viewDidLoad];
19.
<strong>self.tableView.tableFooterView=[[UIView alloc]init];
//关键语句
20.
</strong>
21.
}
22.
23.
#pragma mark - Table view data source
24.
25.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
26.
return
1
;
27.
}
28.
29.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
30.
return
3
;
31.
}
32.
33.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
34.
{
35.
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@
"cell"
forIndexPath:indexPath];
36.
return
cell;
37.
}
38.
39.
@end
本文出处:http://blog.csdn.net/yangbingbinga