Я вложил в подкласс UICollectionViewCell
, заполнил пользовательский интерфейс gridItem
Завершение приложения из-за необработанного исключения
'NSInvalidArgumentException', причина: '- [__ NSCFDictionary gridTitle]:
нераспознанный селектор отправлен на экземпляр 0x1c4a76ec0 '
*** Первый вызов стека вызовов:
(0x1829dad8c 0x181b945ec 0x1829e8098 0x1829e05c8 0x1828c641c 0x100e8712c 0x100e8a4f0 0x18c701fb8 0x18c6e7454 0x18c6e0790
0x18c5af770 0x186b5125c 0x186b553ec 0x186ac1aa0 0x186ae95d0
0x186aea450 0x182982910 0x182980238 0x182980884 0x1828a0da8
0x184883020 0x18c88178c 0x100e6ae54 0x182331fc0)
libc ++ abi.dylib: завершается с необработанным исключением типа NSException
- (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView
cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
UICollectionViewCell *gridCell = nil;
HDZGoodsGridCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:HDZGoodsGridCellID forIndexPath:indexPath];
cell.gridItem = _gridItem[indexPath.row];
cell.backgroundColor = [UIColor whiteColor];
gridCell = cell;
}
return gridCell;
}
#import <UIKit/UIKit.h>
@class HDZGridItem;
@interface HDZGoodsGridCell : UICollectionViewCell
@property (strong , nonatomic)HDZGridItem *gridItem;
@end
#import "HDZGoodsGridCell.h"
#import "HDZGridItem.h"
#import "UIColor+HDZColorTranslation.h"
#import <UIImageView+WebCache.h>
@interface HDZGoodsGridCell()
/* imageView */
@property (strong , nonatomic)UIImageView *gridImageView;
/* gridLabel */
@property (strong , nonatomic)UILabel *gridLabel;
/* tagLabel */
@property (strong , nonatomic)UILabel *tagLabel;
@end
@implementation HDZGoodsGridCell
#pragma mark - Setter Getter Methods
- (void)setGridItem:(HDZGridItem *)gridItem
{
_gridItem = gridItem;
// !!! The following line of code crashes !!!
_gridLabel.text = gridItem.gridTitle;
_gridLabel.text = gridItem.gridTitle;
_tagLabel.text = gridItem.gridTag;
_tagLabel.hidden = (gridItem.gridTag.length == 0) ? YES : NO;
if (_gridItem.iconImage.length == 0) return;
if ([[_gridItem.iconImage substringToIndex:4] isEqualToString:@"http"]) {
[_gridImageView sd_setImageWithURL:[NSURL URLWithString:gridItem.iconImage]placeholderImage:[UIImage imageNamed:@"default_49_11"]];
}else{
_gridImageView.image = [UIImage imageNamed:_gridItem.iconImage];
}
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setUpUI];
}
return self;
}
- (void)setUpUI
{
_gridImageView = [[UIImageView alloc] init];
_gridImageView.contentMode = UIViewContentModeScaleAspectFill;
[self addSubview:_gridImageView];
_gridLabel = [[UILabel alloc] init];
_gridLabel.font = Font13;
_gridLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:_gridLabel];
_tagLabel = [[UILabel alloc] init];
_tagLabel.font = [UIFont systemFontOfSize:8];
_tagLabel.backgroundColor = [UIColor whiteColor];
_tagLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:_tagLabel];
}
@end