简体   繁体   中英

UITableView bottom separator inset - Strange behaviour in IOS 7

My app contains a UITableView which has section footers. When the user scrolls to the bottom of the tableView, sometimes a separator inset appears between the last cell and the tableFooter. This behaviour is inconsistent.

在此处输入图片说明

在此处输入图片说明

Is there a way to force this separator to always appear or never appear? Did any of you noticed this same inconsistent behaviour? Seems like a bug to me.

EDIT
I'm using

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UILabel *footer = [[UILabel alloc] init];

    footer.backgroundColor = [UIColor whiteColor];

    footer.font = [footer.font fontWithSize:15];
    footer.textAlignment = NSTextAlignmentCenter;

    return footer;
}

but you could easily reproduce the same problem only using

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;

在此处输入图片说明

在此处输入图片说明

To do this you'll have to override the standard UIView used as the footer.

You can do this by overriding the delegate method -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section .

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *myFooterView;

    // create a view with a label and without a line at the top etc...

    return myFooterView;
}

I am not sure why you are getting inconsistent results. Maybe try to add a background to your footer view. Here is my code:

-(UIView *) tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 33)];
    [footerView setBackgroundColor:[UIColor grayColor]];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, footerView.bounds.size.width, 20)];
    label.text = @"Footer";
    [label setTextAlignment:NSTextAlignmentCenter];

    [footerView addSubview:label];

    return footerView;
}

And here is the result:

在此处输入图片说明

This is a bit of a lazy way of doing it but it works none the less.

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifyer"];

    if (indexPath.row == tableArray.count) {
         cell.separatorStyle = UITableViewCellSeparatorStyleNone;
    }

    return cell;

}

here is the solution, very easy!

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifyer"];

    cell.separatorInset = (indexPath.row == totalNumber-1) ? UIEdgeInsetsMake(0, INT16_MAX, 0, 0) : UIEdgeInsetsZero;

    return cell;

}

I found some workaround about it:

Whenever you expect this extra separator could appear (for example, when user scrolls to the bottom like you described) - add these lines of code:

tableView.separatorStyle = UITable​View​Cell​Separator​Style​None;
tableView.separatorStyle = UITable​View​Cell​Separator​Style​Single​Line;

The logic is something like that: first string of code removes bottom separator, and the second one doesn't add it. It worked for me in some cases, but it is not a 100% fix.

I guess, it might be an Apple bug also, as sometimes bottom separator disappears in their 'Reminders' app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM