ios开发技巧之tableView去掉多余的空行分割线 自定义cell分割线

如何去掉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
可以看到本来只有3行数据,却显示了很多行的空白分割线,如何去掉?

 

方法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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值