防止cell中添加控件重复

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdetify = @"cell";
UITableViewCell *tvCell = [tableView dequeueReusableCellWithIdentifier:cellIdetify];

if(tvCell == nil)
{
    NSLog(@"cell = nil");
    tvCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdetify] autorelease];
}else{     //如果不增加下面这个判断,tableview 再滑动后,会有重影,或者在被选中后会有重影
    NSLog(@"cell !=nil ");
    NSArray *views = [tvCell subviews];
    for (UIView *obj in views) {
        if (obj.tag==1000 || obj.tag==2000) {
            NSLog(@"cell 要删除的子画面是:%@",[obj class]);
            [obj removeFromSuperview];
        }
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容