3

I have an application with dynamic data loaded into a tableview. When there is only one item (thus only one cell). To make sure that the UITableViewCellSeperator is not showing up for this one item I am using this code:

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {

    // This will create a "invisible" footer
    return 0.01f;

}

This works as expected and here is what my cell looks like:

Cell with no issue

As you can see this works as expected and there is no cell separator.

When I select the cell and display my detail view and then hit the back button, the cell adds a separator for some reason. Here is what the cell looks like once I navigate back in the stack:

Cell with issue

You will notice that the separator is now wider than the standard separator. If my tableview has more than one cell in it, the last cell in the tableview will behave this same way.

When I remove the above method, the issue is fixed, but now my tableview has a TON of extra separators for empty cells. Is there a better solution?

Here is my cellForRowAtIndexPath method:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"searchCell";
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...

    cell.backgroundColor = [UIColor PFBlack];

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    cell.textLabel.font = [MuseoSans font500WithSize:16.0f];
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.textLabel.text = @"Current Location";


    return cell;

}

Any idea what is causing the issue? Or am I doing something wrong? Thanks!

Kyle Begeman
  • 7,169
  • 9
  • 40
  • 58

2 Answers2

0

This should remove your extra cell separators:

tableVie.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

source

Community
  • 1
  • 1
Mike S
  • 11,329
  • 6
  • 41
  • 76
  • This does remove the separators, but when I push something onto the stack and then pop it back off, the larger/wider separator at the bottom cell reappears still. – Kyle Begeman Jan 22 '14 at 19:12
0

you can do this by following two way

First is

[self.tbl setSeparatorStyle:UITableViewCellSeparatorStyleNone];

Second is

change your tableview property from "default"
enter image description here
to "none"
enter image description here

Haresh Ghatala
  • 1,996
  • 17
  • 25
  • This will completely remove the separators. I still want them to be in the tableview, I just don't want the excess separators to show up. If I have two items, the separator will show up as if there are 5 cells. – Kyle Begeman Jan 22 '14 at 19:11