美文网首页
iOS 自定义tableView的cell上,控件重复创建的问题

iOS 自定义tableView的cell上,控件重复创建的问题

作者: 达_Ambition | 来源:发表于2018-07-18 14:34 被阅读29次

修改前:(自定义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上下滑动式,重复创建,如下图:


1.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];
}

相关文章

网友评论

      本文标题:iOS 自定义tableView的cell上,控件重复创建的问题

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