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

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

我似乎无法解决的是自定义单元格不是实际表格单元格的全宽,因此只显示白色背景.如果我不使用自定义单元格,则可以使用整个宽度表单元格.

我为单元格内容设置了约束,以便背景图像填充单元格.

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

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)After that select both image and label and do as below

2) Select the image and do below

3) select the label an do the following

你能查看下面的链接

Table cell content(title) moving left after selecting cell

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...