美文网首页
防止cell中添加控件重复

防止cell中添加控件重复

作者: Flutter求学者 | 来源:发表于2017-08-29 16:06 被阅读0次

    -(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];
            }
        }

    相关文章

      网友评论

          本文标题:防止cell中添加控件重复

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