Ios NSMutableArray在自定义单元实现中出现问题

Ios NSMutableArray在自定义单元实现中出现问题,ios,uitableview,nsmutablearray,Ios,Uitableview,Nsmutablearray,所以我在我的特别咖啡馆里有这个密码 #import <UIKit/UIKit.h> #import "AFImagePager.h" @interface SpecialOfferCell : UITableViewCell<AFImagePagerDataSource,AFImagePagerDelegate> @property (nonatomic, retain) NSMutableArray *arrayImages; @property (nonatomic)

所以我在我的特别咖啡馆里有这个密码

#import <UIKit/UIKit.h>
#import "AFImagePager.h"
@interface SpecialOfferCell : UITableViewCell<AFImagePagerDataSource,AFImagePagerDelegate>
@property (nonatomic, retain) NSMutableArray *arrayImages;
@property (nonatomic) NSInteger offer_id;
-(void)loadImages;
@property (weak, nonatomic) IBOutlet AFImagePager *imageIcons;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *descLabel;

@end
所以我要在这里实现的是,当电池加载了图像,它不会再加载。

在您的特殊工作中,您需要实施
prepareforuse
在这里您可以重置任何数据,如图像数组首先,这部分代码是无用的:

if (cell == nil)
{
     cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}
您应该创建新单元格,而不是再次将其出列

我不知道你真正想要的是什么。有两种选择:

  • prepareforeuse
    中,您可以使用
    loadImages
    删除图像以再次加载它们
  • 您不会删除图像-在这种情况下,当单元被重用时,它之前加载了图像,所以基本上是随机的

  • 但如果您只需要从服务器加载图像一次,则可以创建字典,每次在
    loadImages
    中检查图像是否已加载,并从字典中获取它们。我理解的对吗?

    您好,您能不能也粘贴表视图数据源实现代码?您好@Nagamaleshmadali我已经更新了代码。谢谢。但是重置数据会导致方法反复调用loadImages。就我而言,在第三个牢房之后。最好的方法是什么?谢谢。单元格的每个部分都包含不同的图像,因此我在这里使用了AFImagePager,因此我将每个报价的id传递给SpecialOfferCell.m,以便根据其报价id加载图像。解决方案1,我不打算删除图像,我只想在将所有图像加载到每个单元格时,不会再次加载图像。解决方案2,第三个单元格将包含来自第一个单元格的图像。因此,您需要做的是在某个字典中保留对图像数组的引用,其中键是您的提供名称或其他唯一标识符(例如indexPath),在“loadImages”中,您尝试从字典中加载图像,并在字典[yourKey]为空时从服务器加载图像。我对你的问题理解正确吗?
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
     {
     NSDictionary * Object=[[NSDictionary alloc]init];
     Object=[array objectAtIndex:indexPath.row];
     static NSString *CellIdentifier = @"SpecialOfferCell";
     SpecialOfferCell *cell = (SpecialOfferCell *)[tableView
                                           dequeueReusableCellWithIdentifier:CellIdentifier];
    
     cell.titleLabel.text=[Object objectForKey:@"offer_title"];
     [cell setOffer_id:[[Object objectForKey:@"offer_id"]integerValue]];
    
     [cell performSelectorInBackground:@selector(loadImages) withObject:nil];
    
     return cell;
     }
    
    if (cell == nil)
    {
         cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    }