如何在不使用重用标识符的情况下创建自定义单元

时间:2015-02-02 13:55:10

标签: ios objective-c uitableview

我正在创建一个程序,我在其中从URL获取图像并在自定义单元格上显示,其余表格数据显示在其他单元格上。

以下是代码:

image=[[UIImage alloc]init];

if(indexPath.row==0)
{

    LabelTableViewCell *cell=[detailtable dequeueReusableCellWithIdentifier:@"imagecell" forIndexPath:indexPath];


    NSOperationQueue *myqueue=[[NSOperationQueue alloc] init];
    NSBlockOperation *downloadOperation = [NSBlockOperation blockOperationWithBlock:^{
        [cell.actindi startAnimating];
        image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[frontimage objectAtIndex:0]]]];

    }];
    downloadOperation.completionBlock=^{
        cell.imageprimary.image=image;
    [cell.actindi stopAnimating];

    };
    [myqueue addOperation:downloadOperation];


        return cell;
    }
else
{
        LabelTableViewCell *cell = [detailtable dequeueReusableCellWithIdentifier:@"tabledetail" forIndexPath:indexPath];
        cell.labelspec.text=[firstArray objectAtIndex:indexPath.row];
        cell.txtfield.text=[secondArray1 objectAtIndex:indexPath.row];

    return cell;

}
return 0;

我面临的问题:

  1. 每当我向上滚动它重新加载顶部单元格。
  2. 在点击该单元格之前,它不会在第一个单元格上重新加载图像。
  3. if(!cell)if (cell==nil)无效。
  4. 重新加载表会进入无限循环,直到我向下滚动。
  5. 所以我想永久地将内存分配给第一个单元格,因为它只有一个。

    我已经尝试将nil放入dequeueReusableCellWithIdentifier并且无效。

    我已经做了大约20-30篇文章,但没有任何对我有用我不知道为什么。

    所以请在目前情况下给我任何具体的解决方案。 我是iOS新手,我不太了解它。这是我想要制作的第一个节目。

1 个答案:

答案 0 :(得分:1)

你可以尝试不同的方式:

下载并显示图片只需使用库 - https://github.com/rs/SDWebImage

Library将为您下载图像和缓存。

相关问题