iOS自定义UITableCell自定义分割线消失问题

来源:互联网 发布:mysql 生成连续数字 编辑:程序博客网 时间:2024/06/06 13:12

iOS自定义的UITableCell自定义的分割线,在cell复用的时候,cell的分割线会消失。

这样的问题是,你把你的分割线自定义在每个cell上,当cell服用的时候,只会读取你的数据模型的数据,但是你的分割线不会重新划线,如:

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier {

self= [superinitWithStyle:stylereuseIdentifier:reuseIdentifier];

if(self) {

//你的cell复用分割线消失是因为,你在这里添加的分割线

}

}

解决办法:(在你的自定的cell中实现该方法,来添加分割线)

- (void)drawRect:(CGRect)rect {

CGContextRefcontext =UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [UIColorclearColor].CGColor);

CGContextFillRect(context, rect);

//上分割线,

//CGContextSetStrokeColorWithColor(context, COLORWHITE.CGColor);

//CGContextStrokeRect(context, CGRectMake(5, -1, rect.size.width - 10, 1));

//下分割线

CGContextSetStrokeColorWithColor(context,COLORSEPLINE.CGColor);

CGContextStrokeRect(context,CGRectMake(0, rect.size.height-0.5, rect.size.width,1));


}
0 0
原创粉丝点击