当UITableViewCell重新加载时,iOS Image会消失

时间:2013-08-14 08:34:48

标签: ios uitableview cell

第一次一切正常,更新方法工作正常,但如果我向下滚动,然后向上内容图像消失。

   if(indexPath.row ==2){

        UIImageView *ArticleImageim = [[UIImageView alloc] init];
        ArticleImageim.frame = CGRectMake(10, 0, self.view.frame.size.width-20, (int)self.ImageHeightInCell); //at first self.ImageHeightInCell is 0
        if(self.image == NULL) //in first load I download an image
            {
                NSURL *url = [[NSURL alloc] initWithString:[JSONDict objectForKey:@"slika"]];
                NSData *imageData = [NSData dataWithContentsOfURL:url];
                self.image = [UIImage imageWithData:imageData];
                [ArticleImageim setImage:self.image];
                self.ImageHeightInCell = (int)((self.image.size.height*ArticleImageim.frame.size.width)/self.image.size.width); //Update the self.ImagHeightInCell variable and reload the tableview data.
                [self.tableView beginUpdates];
                [self.tableView endUpdates];
            }
        else //In this block the self.image and the self.ImagHeightInCell are both set.
            {
                [ArticleImageim setImage:self.image];
            }
        ArticleImageim.contentMode = UIViewContentModeScaleAspectFit;
        [cell addSubview:ArticleImageim];
        return cell;
        }

解决方案:我复制了

  

ArticleImageim.frame = CGRectMake(10,0,self.view.frame.size.width-20,(int)self.ImageHeightInCell);

里面的

  

if(self.image == NULL)

现在它的工作。 (但我不知道为什么......)

0 个答案:

没有答案