1

I have a UICollectionViewCell subclass, which displays only a UIView subview with a background color right now, to show that it's there.

In order to load from the XIB, I have to replace this:

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.localPlayerItemsView registerClass:[MBTradeCollectionViewCell class]
                  forCellWithReuseIdentifier:CellIdentifier];
}

with this:

- (void)viewDidLoad {
    [super viewDidLoad];
    UINib *nib = [UINib nibWithNibName:@"MBTradeCollectionViewCell" bundle:nil];

    [self.localPlayerItemsView registerNib:nib forCellWithReuseIdentifier:CellIdentifier];
}

Upon doing that, I then get a crash on the first line in collectionView:cellForItemAtIndexPath::

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    MBTradeCollectionViewCell *aCell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier
                                                                                forIndexPath:indexPath];

    return aCell;
}

Here's the crash:

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x7d461780> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key itemCountView.'

It doesn't cause this crash when using registerClass:forCellWithReuseIdentifier:, but then it doesn't load my xib.

Andrew
  • 7,693
  • 11
  • 43
  • 81
  • Check your custom cell Outlet Connections for itemCountView. – BhushanVU Oct 17 '14 at 14:31
  • Sounds like an IBOutlet is hooked up incorrectly. Check all the connections in your nib. – Rayfleck Oct 17 '14 at 14:41
  • Possible duplicate of [What does this mean? "'NSUnknownKeyException', reason: ... This class is not key value coding-compliant for the key X"](http://stackoverflow.com/questions/3088059/what-does-this-mean-nsunknownkeyexception-reason-this-class-is-not-key) – Quinn Taylor Feb 16 '16 at 17:29

3 Answers3

5

In your MBTradeCollectionViewCell xib file, do not change anything with file's owner. Change the top most view's class to MBTradeCollectionViewCell, and select itemCountView, connect it to your top most view. Hope this will resolve the issue.

gabbler
  • 13,626
  • 4
  • 32
  • 44
3

This crash usually occurs when you have a broken outlet. Check your nib file for the outlet with name itemCountView which would be broken(not connected properly). Which will appear with red mark.

Anil Varghese
  • 42,757
  • 9
  • 93
  • 110
1

I fixed it.

I went into assistant mode, and dragged from the property to IB, and it offered me the options ‘file’s owner’ or ‘trade collection view’?

I picked the bottom one, which means that those things weren’t hooked up in file’s owner, but it turns out that they're visible in trade collection view also, and they are hooked up there.

And it works.

Andrew
  • 7,693
  • 11
  • 43
  • 81