UICollectionViewCell图像未出现在自定义键盘中

时间:2016-06-20 18:40:39

标签: ios objective-c uicollectionviewcell custom-keyboard

我无法在自定义键盘内的uicollectionviewcell中加载我的图片。创建自定义键盘时,您将获得KeyboardViewController.h和KeyboardViewController.m文件。在我的KeyboardViewController.m文件中,我有以下内容:

- (KeyboardCollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
KeyboardCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CELL" forIndexPath:indexPath];
UIImageView *emojiImageView = [[UIImageView alloc] init];
emojiImageView.image = [self.emojiIcons objectAtIndex:indexPath.row];
[cell addSubview:emojiImageView];


if (indexPath.row % 2 == 0) {
    cell.backgroundColor = [UIColor redColor];
} else {
    cell.backgroundColor = [UIColor blueColor];
}

return cell;

}

在我的viewDidLoad中,我概述了我的图像数组:

self.emojiIcons = [NSArray arrayWithObjects:@"skull", @"skull", @"skull", @"skull", @"skull", @"skull", @"skull", @"skull", @"skull", @"skull", @"skull", @"skull", @"skull", @"skull", @"skull", @"skull", nil];

在我的KeyboardCollectionViewCell.h中,我有以下内容:

@property (weak, nonatomic) IBOutlet UIImageView *emojiImageView;

我可以让细胞的背景颜色发生变化,但图像不会加载。关于为什么我的图像没有出现的任何想法?

1 个答案:

答案 0 :(得分:0)

尝试替换此行

emojiImageView.image = [self.emojiIcons objectAtIndex:indexPath.row];

with ..

[cell.emojiImageView setImage:[self.emojiIcons objectAtIndex:indexPath.row]];
相关问题