0

I have two different custom cell in my tableview, In the first cell I add a custom cell line under the system cell line:

_bottom_line = [[UIView alloc] initWithFrame:CGRectMake(0, 49, kScreen_Width, 1)];
_bottom_line.backgroundColor = Back_Color_QQ;
[part3 addSubview:_bottom_line];

In the controller to setup my custom cell;

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.section == 0) {  // my first cell
        
        static NSString *id_cell1 = @"cell1";
        AgDetailTechCell *cell = [tableView dequeueReusableCellWithIdentifier:id_cell1];
        if (cell == nil) {
            cell = [[AgDetailTechCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:id_cell1];
        }
        
        ((AgDetailTechCell *)cell).model = self.headerModel;
        ((AgDetailTechCell *)cell).indexPath = indexPath;
        ((AgDetailTechCell *)cell).delegate = self;
        _head_cell = cell;
        
        _head_cell.comemntCountlabel.text = self.headerModel.lml_commentTimes;
        _head_cell.likeCountlabel.text = self.headerModel.lml_likeTimes;
        
        return cell;
    }else {  // other cells
    
        static NSString *id_cell2 = @"cell2";
        AgPreOrHelpCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:id_cell2];
        if (cell == nil) {
            //cell = [[AgPreOrHelpCommentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:id_cell2];
            cell = [[NSBundle mainBundle] loadNibNamed:@"AgPreOrHelpCommentCell" owner:self options:nil].firstObject;
        }
        cell.delegate = self;
        cell.indexPath = indexPath;
        [cell initCellDataWithModel:self.dataSource[indexPath.row]];
        
        
        cell.refresh = ^(UITableViewCell *currentCell) {
            
        
            [self.tableView reloadData];
            
             [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO];
            
        };
        
        
        return cell;
    }
    
}

The first time into the controller, it shows well. But after I scroll my tableview to hide and show again, my custom bottom line dismiss, I cannot find it.And I refresh my tableView, the custom line appears again. I have token 2 pictures to explain more detail:

UPDATE Use Harsh's suggestion, but no change for the issue:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

    if ([cell.reuseIdentifier isEqualToString:@"cell1"]) {
        // customs bottom_line
         UIView * bottom_line = [[UIView alloc] initWithFrame:CGRectMake(0, 49, kScreen_Width, 1)];
        bottom_line.backgroundColor = Back_Color_QQ;
        
        [((AgDetailTechCell *)cell).part3 addSubview:bottom_line];
    }
    
}
aircraft
  • 25,146
  • 28
  • 91
  • 166
  • Try to add the lines in the `willDisplayCell` dataSource method. I hope you will get the right result. – Harsh Aug 11 '16 at 03:16
  • @Harsh I have taken your suggestion, but it shows no change, thanks all the time. – aircraft Aug 11 '16 at 03:25
  • Could you highlight in the image which line you are talking about. – Harsh Aug 11 '16 at 03:28
  • @Harsh In my update code. – aircraft Aug 11 '16 at 03:33
  • Sorry for the miscommunication, i wanted you to point it on the image which you have attached. I am not able to see the lines in the images you are talking about. – Harsh Aug 11 '16 at 03:35
  • @Harsh I have update my image, thanks your remind.BTW, I take your method, I found if I scroll my` tableview` down to dismiss the first cell and up to show it, it is well, but I up to dismiss the first cell and down to show it, it will goes wrong . – aircraft Aug 11 '16 at 03:41
  • The reason for adding this kind of line is to make the separator appear end to end? – Harsh Aug 11 '16 at 03:46
  • @Harsh. Right, our UI want the line reach the left and right. – aircraft Aug 11 '16 at 03:48
  • Then my dear friend your approach of adding your own line is totally incorrect. Apple provides a way to extend the default line. :) – Harsh Aug 11 '16 at 03:52
  • http://stackoverflow.com/questions/18773239/how-to-fix-uitableview-separator-on-ios-7 – Harsh Aug 11 '16 at 03:53
  • @Harsh, Ohh, Harsh, So I'm ignorant to the extend the default line. – aircraft Aug 11 '16 at 03:55
  • So does this solve your purpose? – Harsh Aug 11 '16 at 03:57
  • @Harsh , I found the kind link I have read before, and I cannot make a positive cell to expand its bottom line. – aircraft Aug 11 '16 at 04:03
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/120648/discussion-between-qq726535609-and-harsh). – aircraft Aug 11 '16 at 04:08

2 Answers2

1

If your soul purpose is to extend the default separators from end to end.

Check this post How to fix UITableView separator on iOS 7?

Community
  • 1
  • 1
Harsh
  • 2,852
  • 1
  • 13
  • 27
0

Maybe your bottom line is out of your cell. Make sure you return 50 or greater height for cells. Another thing is disable the system bottom line of UITableView.

Harrison Xi
  • 766
  • 1
  • 5
  • 23
  • I have `lldb` the cell, its height no change, and I `capture view hierarchy `, it shows no my `custom bottom line`. – aircraft Aug 11 '16 at 03:52
  • Was the bottom line removed from it's superview? You'd better make a demo project for this issue. Then we well be able to debug it. – Harrison Xi Aug 11 '16 at 03:58