【发布时间】:2015-08-18 11:14:37
【问题描述】:
我可能做错了。因此,我创建了一个 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];
【问题讨论】:
-
检查单元格背景图片的大小。我猜这是自动布局的问题。
-
细胞本身就是如此。如果它只是一个背景图像问题,那么标签就不会出现在它所在的位置。它会一直向右。
-
给单元格颜色并确定单元格大小
-
在单元格的 contentView 上设置背景颜色。检查 imageView 是否对表格的内容视图设置了尾随?
-
@JoshYork 你能分享你的代码吗?
标签: ios objective-c uitableview autolayout