我可能做错了。所以我创建了一个 UITableView,它基本上有一个自动布局尾随空间设置为主视图。我正在为此表创建一个自定义单元格,因此我在原型(prototype)单元格上添加了药物,对其进行了自定义,并为其创建了我的类。这一切都很好。
我似乎无法解决的是自定义单元格没有占据实际表格单元格的整个宽度,因此只会显示白色背景。如果我不使用自定义单元格,则会使用整个宽度表格单元格。
我为单元格内容设置了约束,以便背景图像填充单元格。
我做错了什么?让我知道您需要什么来帮助解决这个问题。
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];
最佳答案
你能把代码贴出来吗?
您是否启用了使用自动布局和使用尺寸分类,如下所示,首先在表格 View 和表格 View 单元格中执行此操作。然后告诉我您的问题
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
你能查看下面的链接吗:
关于iOS - 自定义表格单元格不是 UITableView 的全宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30633739/