美文网首页iOS
iOS自定义UITableCell自定义分割线消失问题

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

作者: oneDemo | 来源:发表于2015-12-24 16:46 被阅读1593次

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));

}

相关文章

网友评论

  • a0a73949697b:drawRect:(CGRect)rect这个方法在真机iOS7.1.2分割线无法显示怎么破啊?

本文标题:iOS自定义UITableCell自定义分割线消失问题

本文链接:https://www.haomeiwen.com/subject/kubvhttx.html