UITableViewCell Separator disappearing in iOS7

前端 未结 30 709
轮回少年
轮回少年 2020-12-07 08:31

I have some strange issue with UITableView only in iOS 7.

UITableViewCellSeparator disappears above the first row and below the last row. S

相关标签:
30条回答
  • 2020-12-07 09:11

    I've resolved putting these lines of code where the update of the tableview hapens:

    self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyle.SingleLine;
    

    For example, in my case i've putted them here:

    tableView.beginUpdates()
    tableView.insertRowsAtIndexPaths(insertIndexPaths, withRowAnimation: UITableViewRowAnimation.Fade)
    tableView.endUpdates()
    self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyle.SingleLine;
    
    0 讨论(0)
  • 2020-12-07 09:11

    ran into a similar problem, I found that another good solution, especially if your dataSource is not large is reload the tableData when you implement the -(void)scrollViewDidScroll:(UIScrollView *)scrollView method, here's an example:

    -(void)scrollViewDidScroll:(UIScrollView *)scrollView {
          if (scrollView == self.tableView1) {
              [self.tableView1 reloadData];
          }
    
          else {
              [self.tableView2 reloadData];
          }
    }
    

    You can also just reload non-visible data based on the visible dataSource, but that requires some more hacking.

    Keep in mind this delegate function falls under the UITableViewDelegate protocol!

    Hope it helps!

    0 讨论(0)
  • 2020-12-07 09:12

    Here is an easier (although a bit messy) workaround if you need one, try selecting and deselecting the cell after the data is reloaded and the default animation is done.

    just add:

    [self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    0 讨论(0)
  • 2020-12-07 09:13

    I tried so many suggestions to fix but cannot fix that.Finally I decided to custom separator line as below:

    func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
        var lineView = UIView(frame: CGRectMake(20, cell.contentView.frame.size.height - 1.0, cell.contentView.frame.size.width - 20, 1))
    
        lineView.backgroundColor = UIColor(red: 170.0/255.0, green: 170.0/255.0, blue: 170.0/255.0, alpha: 1)
        cell.contentView.addSubview(lineView)
    }
    

    P/S: custom at willDisplayCell NOT cellForRowAtIndexPath

    0 讨论(0)
  • 2020-12-07 09:14

    Going through the answers and solutions I came up with such observations:

    This seems to be problematic in both iOS 7 and 8. I noticed the problem when selecting cell from code in viewDidLoad method so:

    1) workaround was doing so in viewDidAppear: if someone doesn't mind the noticeable delay between presenting the view and selecting the cell

    2) the second solution worked for me but the code looks a bit fragile as it base on the internal implementation of the UITableViewCell

    3) adding own separator seems to be the most flexible and best for now but require more coding :)

    0 讨论(0)
  • 2020-12-07 09:16

    I solve this problem in another way: add a layer that its height is 0.5px and its color is lightgray into tableview.tableFooterView as its sublayer.

    the code is just like this:

    UIView *tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 70)];
    CALayer *topSeperatorLine = [CALayer layer];
    topSeperatorLine.borderWidth = 0.5f;
    topSeperatorLine.borderColor = [UIColor lightGrayColor].CGColor;
    topSeperatorLine.frame = CGRectMake(0, 0, 320, 0.5f);
    [tableFooterView.layer addSublayer:topSeperatorLine];
    self.tableView.tableFooterView = tableFooterView;
    
    0 讨论(0)
提交回复
热议问题