修改前:(自定义tableViuewCell的时候)在cell的.h文件中,创建控件
- (void)setupTagsViewWithArray:(NSArray *)array{
_textTagsView = [[TextTagsView alloc]initWithFrame:CGRectMake(0, 0,CGRectGetWidth(_tagsView.frame) ,20) dataArr:array font:14];
_textTagsView.backgroundColor = [UIColor whiteColor];
[_tagsView addSubview:_textTagsView];
}
导致当tableView上下滑动式,重复创建,如下图:
![](https://img.haomeiwen.com/i11989677/c3609f75c886be9f.png)
修改代码:
- (void)setupTagsViewWithArray:(NSArray *)array{
if (!_textTagsView) {
_textTagsView = [[TextTagsView alloc]initWithFrame:CGRectMake(0, 0,CGRectGetWidth(_tagsView.frame) ,20) dataArr:array font:14];
_textTagsView.backgroundColor = [UIColor whiteColor];
}
[_tagsView addSubview:_textTagsView];
}
网友评论