【问题标题】:UICollectionViewCell Images Not Appearing in Custom KeyboardUICollectionViewCell 图像未出现在自定义键盘中
【发布时间】: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


    【解决方案1】:

    尝试替换此行

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

    用..

    [cell.emojiImageView setImage:[self.emojiIcons objectAtIndex:indexPath.row]];
    

    【讨论】:

      猜你喜欢
      • 2013-11-11
      • 1970-01-01
      • 1970-01-01
      • 2017-10-04
      • 2018-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-14
      相关资源
      最近更新 更多