0

I am having trouble getting my images to load in uicollectionviewcell inside of my custom keyboard. When you create a custom keyboard, you are given a KeyboardViewController.h and KeyboardViewController.m files. Inside of my KeyboardViewController.m file I have the following:

- (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;

}

In my viewDidLoad I have outlined my array of Images:

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

In my KeyboardCollectionViewCell.h I have the following:

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

I can get the background color of the cells to changes, but the images won't load. Any ideas as to why my images aren't showing up?

a2b123
  • 573
  • 1
  • 5
  • 19

1 Answers1

0

Try replacing this line

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

with ..

[cell.emojiImageView setImage:[self.emojiIcons objectAtIndex:indexPath.row]];
Saheb Singh
  • 555
  • 4
  • 18