iOS自定義的UITableCell自定義的分割線,在cell復(fù)用的時候,cell的分割線會消失。
這樣的問題是,你把你的分割線自定義在每個cell上,當(dāng)cell服用的時候,只會讀取你的數(shù)據(jù)模型的數(shù)據(jù),但是你的分割線不會重新劃線,如:
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier {
self= [superinitWithStyle:stylereuseIdentifier:reuseIdentifier];
if(self) {
//你的cell復(fù)用分割線消失是因為,你在這里添加的分割線
}
}
解決辦法:(在你的自定的cell中實現(xiàn)該方法,來添加分割線)
- (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));
}