UITableView 缺少一些分隔线 [英] UITableView some separator line missing

查看:16
本文介绍了UITableView 缺少一些分隔线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用代码构建一个像这样的 uitableview:

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"];

还有 dataresource 和 viewdelegate

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.

那么可能是什么导致了这个问题?

So what may have caused this problem?

对于那些可能会担心的人,此屏幕截图不是在模拟器上而是在 ihpone 设备上捕获的.

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.

推荐答案

您似乎在使用自定义单元格类.如果您在单元类实现中覆盖 layoutSubviews() 方法,请确保在该方法中具有以下内容:

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()

或在 Objective-C 中:

or in Objective-C:

[super layoutSubviews];

这为我解决了问题.

这篇关于UITableView 缺少一些分隔线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆