0

我有一个 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;
}

我收到以下错误:

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

4

3 回答 3

1

我通过添加来修复它:

@synthesize 代表;

Product.m

于 2013-10-10T16:56:07.093 回答
0

来自产品的对象_redWineArray[indexPath.row];肯定是产品的实例吗?

//不正确使用@property(nonatomic, weak) id<CWProductDelegate> delegate;

于 2013-10-09T23:50:47.743 回答
0

这是你的Product.h,它定义了类的public propertiesand 。methodsProduct

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

这不包括setDelegate:方法。如果您在 y 中包含此方法

于 2013-10-09T23:51:26.263 回答