Issues with UITableViewCellSeperator reappearing after popping from the stack

做~自己de王妃 提交于 2019-12-12 08:57:13

问题


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:

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:

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!


回答1:


This should remove your extra cell separators:

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

source




回答2:


you can do this by following two way

First is

[self.tbl setSeparatorStyle:UITableViewCellSeparatorStyleNone];

Second is

change your tableview property from "default"


to "none"



来源:https://stackoverflow.com/questions/21273709/issues-with-uitableviewcellseperator-reappearing-after-popping-from-the-stack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!