1

This is how my UITableView looks like:

enter image description here

I might cut the image to close to the last cell but there is no separator on the last cell.

When running this on my device that has IOS 7.1.1 It gets the same result until i scroll the view up and down a bit and then it automatically adds the separator. But trying that in the simulator which is running on IOS 8.2 as you can se nothing happens.

So what i want is simply so the separator is visible from the start.

Many thanks

EDIT1

After trying the answer below it did work however when there are a lot of cells and you scroll up then an extra separator shows up as you can see.

enter image description here

Check the third last cell. That extra separator just follows me when i go up and down.

EDIT2

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)])
    {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([cell respondsToSelector:@selector(setLayoutMargins:)])
    {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

-(void)viewDidLayoutSubviews
{
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)])
    {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])
    {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 0)
        return 76.0f;
    else
        return 25.0f;
}
Timo Cengiz
  • 3,367
  • 4
  • 23
  • 45
  • do you dynamically calculate the height of each cell? Is it possible that you get fractional heights (< 0.5 pt) from these calculations? If so try to `ceil( )` these values. My separator issues disappeared after I avoided row heights like 22.38947 – Matthias Bauch Mar 24 '15 at 22:20
  • No i have a fixed height that i set for them @MatthiasBauch – Timo Cengiz Mar 24 '15 at 22:50
  • There are so many bugs in `UITableView` separator. I always create my own seperator by adding a line in `UITableViewCell` – Tony Mar 25 '15 at 03:03
  • Would you mind sharing that code? @VietHung – Timo Cengiz Mar 25 '15 at 09:23

3 Answers3

3

Use the two below UITableView delegate methods

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView* view = [UIView new];
[view setBackgroundColor:[UIColor grayColor]];
return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 1.0f;
}
  • Worked perfectly, Thnx – Timo Cengiz Mar 24 '15 at 17:08
  • Are you also implementing the viewForHeader and heightForHeader methods? Do you mind adding all your code that has to do with your table view so I can take a look? – Lee J Pollard Mar 24 '15 at 22:11
  • No i am not implementing those methods, yes i will put all the relevant stuff – Timo Cengiz Mar 24 '15 at 22:51
  • Add `if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) { [cell setPreservesSuperviewLayoutMargins:NO]; }` in the `-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath` method – Lee J Pollard Mar 25 '15 at 03:37
  • Nope the bottom footer still keeps following me. Also edit your answer and insert the code there. it's easier. – Timo Cengiz Mar 25 '15 at 09:20
  • Perhaps this post will help you. It seems very similar to your issue. http://stackoverflow.com/questions/25770119/ios-8-uitableview-separator-inset-0-not-working – Lee J Pollard Mar 25 '15 at 14:24
0

Try to add footer view for table with 1 0r 2 pixel height.

Ram Vadranam
  • 485
  • 5
  • 14
0

This worked flawlessly for me

self.tableFooterView = [[UIView alloc] init]
Timo Cengiz
  • 3,367
  • 4
  • 23
  • 45