Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide remove separator line if UITableViewCells are empty [duplicate]

I have a UITableView and I have only 3 rows in it, and I can see those 3 rows. The problem is the cells that are empty: I can see lines there. I don't want to see those lines.

Any idea how to remove those lines?

Below is image for what I am looking for.

Image Link

like image 262
Fahim Parkar Avatar asked Jan 22 '13 14:01

Fahim Parkar


2 Answers

Even simpler than Andrey Z's reply: Simply make a bogus tableFooterView in your UITableView class:

self.tableFooterView = [UIView new]; // to hide empty cells 

and Swift:

tableFooterView = UIView()

like image 80
T. Benjamin Larsen Avatar answered Sep 20 '22 03:09

T. Benjamin Larsen


You can hide UITableView's standard separator line by using any one of the below snippets of code. The easiest way to add a custom separator is to add a simple UIView of 1px height:

UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)]; separatorLineView.backgroundColor = [UIColor clearColor]; // set color as you want. [cell.contentView addSubview:separatorLineView]; 

OR

    self.tblView=[[UITableView alloc] initWithFrame:CGRectMake(0,0,320,370) style:UITableViewStylePlain];     self.tblView.delegate=self;     self.tblView.dataSource=self;     [self.view addSubview:self.tblView];      UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 10)];     v.backgroundColor = [UIColor clearColor];     [self.tblView setTableHeaderView:v];     [self.tblView setTableFooterView:v];     [v release]; 

OR

- (float)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {     // This will create a "invisible" footer     return 0.01f; }  - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {     // To "clear" the footer view     return [[UIView new] autorelease]; } 

OR

And also check nickfalk's answer, it is very short and helpful too. And you should also try this single line,

self.tableView.tableFooterView = [[UIView alloc] init]; 

Not sure but it's working in all the version of iOS that I checked, with iOS 5 and later, up to iOS 7.

like image 40
iPatel Avatar answered Sep 22 '22 03:09

iPatel