4

I am using code to build a uitableview like this:

UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 290, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 290)]; 
tableView.delegate = self;
tableView.dataSource = self;
[tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"settingtabcell"];

And the dataresource and viewdelegate

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"settingtabcell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }else{
        for(UIView *subview in cell.subviews){
            [subview removeFromSuperview];
        }
    }
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(70, 0, [UIScreen mainScreen].bounds.size.width - 20, 90)];
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 30, 32, 32)];
    
    switch (indexPath.row) {
        case 0:
            label.text = @"Copyright information";
            imageView.image = [UIImage imageNamed:@"copyright.png"];
            break;
        case 1:
            label.text = @"Clear cache";
            imageView.image = [UIImage imageNamed:@"clearcache.png"];
            break;
        case 2:
            label.text = @"Feedback";
            imageView.image = [UIImage imageNamed:@"feedback.png"];
            break;
        case 3:
            label.text = @"About us";
            imageView.image = [UIImage imageNamed:@"about.png"];
            
        default:
            break;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell addSubview:imageView];
    [cell addSubview:label];
    return cell;
}

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 90;
}

The thing is some separator line is missing and some are not, this really confusing me.

enter image description here

So what may have caused this problem?

EDIT

To those who may concern, this screenshot is not on a simulator but was captured on an ihpone device.

And the line was originally showed except that after scrolling down and bouncing back, the line was missing.

Community
  • 1
  • 1
armnotstrong
  • 8,605
  • 16
  • 65
  • 130

4 Answers4

8

It looks like you're using a custom cell class. If you are overriding the layoutSubviews() method in your cell class implementation, make sure that in the method you have the following:

super.layoutSubviews()

or in Objective-C:

[super layoutSubviews];

That solved the problem for me.

Nikita Alexander
  • 527
  • 6
  • 11
3

you can do another way,

  • remove separator line
  • add UILabel with 1px height at end of the cell and set background colour black or light gray (or whatever you want).
Nirav Kotecha
  • 2,493
  • 1
  • 12
  • 26
0

write this line in cellforrowatindexPath

  cell.selectionStyle=UITableViewStylePlain;

and drag n drop a UILabel with view controller Width And Height 1px at the bottom of the content view see the blue line in image

do stuff in storyboard

enter image description here

After reloading table on Device,See image

enter image description here

Vikas Rajput
  • 1,754
  • 1
  • 14
  • 26
0

On my case, it was the Clip To Bounds on the custom UITableViewCell. Accidentally deselected it from the storyboard. Then again setting Clip To Bounds to true resolve this issue. Please do this thing it solve your issue.

Objective-C

[cell setClipToBound: YES];

Swift

cell.clipToBound = true

Storyboard :-

UITableViewCell OR UITableViewCell XIB

enter image description here

Thank You.

Yogesh Patel
  • 1,893
  • 1
  • 20
  • 55