我有一个UICollectionView,每个单元包含一个产品。
当我按需加载图像时,为了保持较低的前期带宽,我想在下载完成后使用产品图像而不是占位符来更新UICollectionViewCell。

所以我有以下几点:

产品h

@class Product;
@protocol CWProductDelegate
-(void)CWProductDidFinishLoadingImages:(Product *)product;
@end

@interface Product : NSManagedObject

@property (nonatomic, retain) NSData * bottleImage;
@property (nonatomic, retain) NSData * bottleImage2x;
@property (nonatomic, strong, getter = chooseBottleImage) NSData * stdBottleImage;
@property (nonatomic, retain) NSNumber * isAvailable;
@property (nonatomic, retain) NSData * labelImage;
@property (nonatomic, retain) NSData * labelImage2x;
@property (nonatomic, strong, getter = chooseLabelImage) NSData * stdLabelImage;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSString * origin;
@property (nonatomic, retain) NSData * pourImage;
@property (nonatomic, retain) NSData * pourImage2x;
@property (nonatomic, strong, getter = choosePourImage) NSData * stdPourImage;
@property (nonatomic, retain) NSDecimalNumber * price;
@property (nonatomic, retain) NSString * productCode;
@property (nonatomic, retain) NSString * productDescription;
@property (nonatomic, retain) NSString * scent;
@property (nonatomic, retain) NSString * setting;
@property (nonatomic, retain) NSString * vintage;
@property (nonatomic, retain) NSString * wineType;
@property (nonatomic, retain) NSString * varietal;
@property (nonatomic, retain) NSManagedObject *lineitem;
@property (nonatomic, retain) NSSet *merchantViews;
@property (nonatomic, weak) id <CWProductDelegate> delegate;
@end

@interface Product (CoreDataGeneratedAccessors)

+ (void)manage:(Product *)product merchantViews:(NSArray *)merchantViews;
+ (NSArray *)redWines;
+ (NSArray *)whiteWines;
+ (NSArray *)whiteRecommendations;
+ (NSArray *)redRecommendations;


- (void)addMerchantViewsObject:(NSManagedObject *)value;
- (void)removeMerchantViewsObject:(NSManagedObject *)value;
- (void)addMerchantViews:(NSSet *)values;
- (void)removeMerchantViews:(NSSet *)values;
- (void)getProductImages;
- (void)fetchRetinaImages;

@end


CWProductCell.h

@interface CWProductCell : UICollectionViewCell <CWProductDelegate>

@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UILabel *productName;
@property (strong, nonatomic) Product *product;


-(void)setLabelText:(NSString *)text;
-(void)addImagesToScrollView;

@end


(CollectionView的东西)

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
  CWProductCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ProductCell" forIndexPath:indexPath];


if (indexPath.row < _redRecommendations)
{
  Product *product = _redWineArray[indexPath.row];
  [product setDelegate:cell];
  ####### THIS IS WHERE THE EXCEPTION IS RISED#####
  cell.product = product;
  cell.productName.text = cell.product.name;

  [cell addImagesToScrollView];

} else {
  Product *product = _whiteWineArray[indexPath.row - _redRecommendations];
  cell.product = product;
  cell.productName.text = cell.product.name;
  [cell addImagesToScrollView];
}
  UITapGestureRecognizer *tapCell = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapCell:)];
  [cell.scrollView addGestureRecognizer:tapCell];


  return cell;
}


我收到以下错误:


  -[产品setDelegate:]:无法识别的选择器已发送到实例0x995f350

最佳答案

我通过添加以下内容进行修复:


  @synthesize委托;


Product.m

关于ios - SetDelegate导致“无法识别的选择器”异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19284632/

10-14 23:18