-(void)layoutSubviews{
// 子视图布局 里一般放一些不改变的东西,静态的,比如说一个label,如果只需要它放在那里颜色位置等属性不变,可以放在layoutSubviews里//但是如果需要后期变它的属性那么就要放在init初始化里
//layoutSubviews 每次移动cell,此方法都会出发,所以每次都会复位,里面设置过的属性都会变回初始值,而设置在init里的不回因为移动cell而去改变cell里的属性。
UISwitch *sw=[[UISwitch alloc]initWithFrame:CGRectMake(220, 2, 45, 45)];
// [self addSubview:sw];
[self.contentView addSubview:sw];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
// 自定义cell初始化
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier{
self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.lable=[[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, 30)];
self.lable.text=@"table000";
self.lable.backgroundColor=[UIColor redColor];
[self.contentView addSubview:self.lable];
self.backgroundColor=[UIColor redColor];
self.contentView.backgroundColor=[UIColor blueColor];
}
return self;
}