Closed GitSmark closed 8 years ago
初始加载数据Cell可以正常显示,刷新或加载数据布局就乱了,应该是我Cell重用的问题,本人新手参考了GSD_WeiXin朋友圈的做法还是找不出问题,请大神指教.... [self.tableView registerClass:[self.cellClass class] forCellReuseIdentifier:Identifier];
@implementation ADWTableViewCell //- (instancetype)initWithFrame:(CGRect)frame { // // if (self = [super initWithFrame:frame]) { // // } // return self; //}
(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self setView]; } return self; }
(void)setView {
CGFloat margin = 10; CGFloat length = 60;
self.head = [[UIImageView alloc] init]; self.name = [[UILabel alloc] init]; self.text = [[UILabel alloc] init]; self.time = [[UILabel alloc] init];
[self addSubview: self.head]; [self addSubview: self.name]; [self addSubview: self.text]; [self addSubview: self.time];
self.head.sd_layout .leftSpaceToView(self, margin) .topSpaceToView(self, margin) .heightIs(length) .widthIs(length);
self.name.sd_layout .leftSpaceToView(self.head, margin) .rightSpaceToView(self, margin) .topSpaceToView(self, margin) .autoHeightRatio(0);
self.text.sd_layout .leftSpaceToView(self.head, margin) .topSpaceToView(self.name, margin) .rightSpaceToView(self, margin) .autoHeightRatio(0);
self.time.font = [UIFont fontWithName:@"Helvetica" size:15]; self.time.textColor = ADGColor; self.time.sd_layout .leftSpaceToView(self.head, margin) .topSpaceToView(self.text, margin) .rightSpaceToView(self, margin) .autoHeightRatio(0);
[self setupAutoHeightWithBottomView: self.time bottomMargin: margin]; self.accessoryType = UITableViewCellAccessoryNone; self.backgroundColor = [UIColor clearColor]; }
完整源码在这里,https://github.com/GitSmark/Void_Add_iOS
先看下SDAutoLayout的视频教程,然后检查下你的约束设置,还有问题的话加入 SDAutoLayout的QQ群497140713找管理员帮你解答下
初始加载数据Cell可以正常显示,刷新或加载数据布局就乱了,应该是我Cell重用的问题,本人新手参考了GSD_WeiXin朋友圈的做法还是找不出问题,请大神指教.... [self.tableView registerClass:[self.cellClass class] forCellReuseIdentifier:Identifier];
@implementation ADWTableViewCell //- (instancetype)initWithFrame:(CGRect)frame { //
// if (self = [super initWithFrame:frame]) { //
// } // return self; //}
(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self setView]; } return self; }
(void)setView {
CGFloat margin = 10; CGFloat length = 60;
self.head = [[UIImageView alloc] init]; self.name = [[UILabel alloc] init]; self.text = [[UILabel alloc] init]; self.time = [[UILabel alloc] init];
[self addSubview: self.head]; [self addSubview: self.name]; [self addSubview: self.text]; [self addSubview: self.time];
self.head.sd_layout .leftSpaceToView(self, margin) .topSpaceToView(self, margin) .heightIs(length) .widthIs(length);
self.name.sd_layout .leftSpaceToView(self.head, margin) .rightSpaceToView(self, margin) .topSpaceToView(self, margin) .autoHeightRatio(0);
self.text.sd_layout .leftSpaceToView(self.head, margin) .topSpaceToView(self.name, margin) .rightSpaceToView(self, margin) .autoHeightRatio(0);
self.time.font = [UIFont fontWithName:@"Helvetica" size:15]; self.time.textColor = ADGColor; self.time.sd_layout .leftSpaceToView(self.head, margin) .topSpaceToView(self.text, margin) .rightSpaceToView(self, margin) .autoHeightRatio(0);
[self setupAutoHeightWithBottomView: self.time bottomMargin: margin]; self.accessoryType = UITableViewCellAccessoryNone; self.backgroundColor = [UIColor clearColor]; }