iOS – 自定义表格单元格不是UITableView的全部宽度

我可能会做这个错误。 所以我创build了一个UITableView,它基本上有一个自动布局的尾部空间设置为主视图。 我正在为这个表格创build一个自定义的单元格,所以我在原型单元格上进行药物定制,并为它创build了我的类。 这一切都工作得很好。

我似乎无法解决的是自定义单元格不是实际表格单元格的全部宽度,所以白色背景只是显示出来。 如果我不使用自定义单元格,则会使用整个宽度表单元格。

我设置单元格内容的约束,以便背景图像应该填充单元格。

我究竟做错了什么? 让我知道你需要什么来帮助解决这个问题。

ProfileCustomCell.h

#import <UIKit/UIKit.h> @interface ProfileCustomCell : UITableViewCell { } @property (nonatomic, strong) IBOutlet UILabel *nameLabel; @property (nonatomic, strong) IBOutlet UIImageView *profileImageView; @end 

ProfileCustomCell.m

 #import "ProfileCustomCell.h" @implementation ProfileCustomCell - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.nameLabel.text = nil; } return self; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; } @end 

UITableView的

 [tableView registerNib:[UINib nibWithNibName:@"ProfileCustomCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"Cell"]; [tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; ProfileCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; cell.nameLabel.text = [NSString stringWithFormat:@"%@", [child objectForKey:@"first_name"]]; [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 

在这里输入图像说明

你可以张贴代码吗?

你是否启用了使用自动布局使用大小类如下所示首先在表视图和表格视图单元格。并告诉我你的问题

在这里输入图像说明

1)之后,select图像和标签,并做如下

在这里输入图像说明

2)select图像,然后执行下面的操作

在这里输入图像说明

3)select标签并执行以下操作

在这里输入图像说明

你可以检查下面的链接:

表格单元格内容(标题)在select单元格后向左移动

select你的表格视图单元的连接检查器,并检查你是否没有连接editAccessoryView错误

在这里输入图像说明

而不是“填充”,自动布局约束到前导和尾随空间为0,并确保它们不相对于边距。