Issues with UITableViewCellSeperator reappearing a

2019-04-12 01:56发布

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!

2条回答
叛逆
2楼-- · 2019-04-12 02:34

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

查看更多
Viruses.
3楼-- · 2019-04-12 02:38

This should remove your extra cell separators:

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

source

查看更多
登录 后发表回答