如何去掉tableView多餘的空白行分割線?
我們經常會遇到下面的問題,tableView表視圖上面的內容不是很多,但是 tableView 卻幫忙把 整個屏幕都用 空白行分割線佔滿了:
如下圖:
代碼如下:
- //
- // TableViewController.m
- // Test
- //
- // Created by on 15/1/25.
- // Copyright (c) 2015年 http://blog.csdn.net/yangbingbinga. All rights reserved.
- //
- #import "TableViewController.h"
- @interface TableViewController ()
- @end
- @implementation TableViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return 3;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
- return cell;
- }
- @end
方法1. 完全去掉所有的分割線,然後 在cell上自定義 一個 view高度爲一個像素,來模擬真實的 分割線
2.方法二,如果不想自定義分割線的話,那就來一個粗暴的方法吧,增加一個 footerView即可解決問題代碼如下:
- //
- // TableViewController.m
- // Test
- //
- // Created by on 15/1/25.
- // Copyright (c) 2015年 http://blog.csdn.net/yangbingbinga. All rights reserved.
- //
- #import "TableViewController.h"
- @interface TableViewController ()
- @end
- @implementation TableViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- <span style="font-size:24px;"><strong>self.tableView.tableFooterView=[[UIView alloc]init];//關鍵語句
- </strong></span>
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return 3;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
- return cell;
- }
- @end
本文出處:http://blog.csdn.net/yangbingbinga