【发布时间】:2014-04-27 14:51:24
【问题描述】:
我有一个嵌入在 UIViewController 中的 UICollectionView (CollectionView) 和一个用于单个单元格的 UICollectionViewCell (子类 - ThemeCell)。
我正在尝试使用来自 imageViews 的 NSArray 的图像填充 UICollectionView 中的每个单元格,但出现以下错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[12]'
我为每个单元格嵌入了一个标签,效果很好。 这是我的行动计划。
在ThemeCell,我有两个属性:
@property (weak, nonatomic) IBOutlet UILabel *cellLabel;
@property (weak, nonatomic) IBOutlet UIImageView *cellImages;
在CollectionViewCell 中,我在.h 中有以下代码:
@property (weak, nonatomic) IBOutlet UICollectionView *cView;
@property (nonatomic, strong) NSArray *themeLabels;
@property (nonatomic, strong) NSArray *themeImages;
这是.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.cView.dataSource = self;
self.cView.delegate = self;
self.themeLabels = [[NSArray alloc] initWithObjects:@"Default", @"Peacock", @"Purple", @"Rainbow", @"Multi Zebra", @"Green", @"Marble", @"Prosperity", @"Leopard", @"Circle", @"Slanted", @"Orange", @"Reddish", nil];
NSLog(@"The themes are %@", self.themeLabels);
self.themeImages = @[[UIImage imageNamed:@"Newiphonebackground.png"], [UIImage imageNamed:@"peacock.png"], [UIImage imageNamed:@"Purplepink.png"], [UIImage imageNamed:@"Rainbow.png"], [UIImage imageNamed:@"PinkZebra.png"], [UIImage imageNamed:@"Greenish.png"], [UIImage imageNamed:@"MarblePrint.png"], [UIImage imageNamed:@"Prosperity.png"], [UIImage imageNamed:@"leopard.png"], [UIImage imageNamed:@"CircleEffect.png"], [UIImage imageNamed:@"RedSlanted.png"], [UIImage imageNamed:@"Orange3.png"], [UIImage imageNamed:@"ReddishBack.png"]];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [self.themeLabels count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
ThemeCell *themeCell = (ThemeCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"Theme Cell" forIndexPath:indexPath];
NSString *cellData = [self.themeLabels objectAtIndex:indexPath.row];
themeCell.cellLabel.text = cellData;
themeCell.cellImages.image = self.themeImages[indexPath.row];
return themeCell;
}
异常断点发生在:
themeCell.cellImages.image = self.themeImages[indexPath.row];
我在情节提要中建立了 CollectionView,并在其中放置了一个单元格并为 Label 和 UIImageView 创建了出口。
标签工作得很好,但图像却不行,而且它正在崩溃。
在这方面的任何帮助都会非常棒并且非常有帮助!
【问题讨论】:
标签: ios iphone uiimageview nsarray uicollectionview