gpt4 book ai didi

ios - SetDelegate 导致 'unrecognized selector' 异常

转载 作者:行者123 更新时间:2023-11-29 03:35:02 26 4
gpt4 key购买 nike

我有一个 UICollectionView,每个 Cells 都有一个 Product。
当我按需加载图像时,为了保持较低的前期带宽,我想在下载完成后更新 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:]: unrecognized selector sent to instance 0x995f350

最佳答案

我通过添加修复了它:

@synthesize delegate;

Product.m

关于ios - SetDelegate 导致 'unrecognized selector' 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19284632/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com