【发布时间】:2016-10-22 03:01:26
【问题描述】:
我无法将图像加载到自定义键盘内的 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;
我可以更改单元格的背景颜色,但无法加载图像。关于为什么我的图片没有显示的任何想法?
【问题讨论】:
标签: ios objective-c uicollectionviewcell custom-keyboard