0

I am doing a project in Objective-C so when I create a custom xib and connect a couple of outlets, it gives me the error:

2023-06-07 22:50:32.194106-0700 ProturisApp[91070:2437111] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<InputCollectionViewCell 0x10403ee78> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key brickWall.'

These are my classes and my extension:

@implementation UIView (NIBLoader)
+ (instancetype)fromNib {
    return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:self options:nil] objectAtIndex:0];
}

@end
#import "InputCollectionViewCell.h"
#define IDENTIFFIER @"InputCollectionViewCell"

@implementation InputCollectionViewCell

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
      if (self) {
          [self loadFromNib];
  
      }
      return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
       if (self) {
           [self loadFromNib];
           self.userInteractionEnabled = YES;
           
           // Initialize what is needed
       }
       return self;
}

+ (NSString *) identifier {
    return IDENTIFFIER;
}


- (void)loadFromNib {
    UIView *nibView = [[self class] fromNib];
    if (nibView) {
        nibView.frame = self.bounds;
        nibView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        [self addSubview:nibView];
        nibView.backgroundColor = [UIColor redColor];
    }
}


@end
#import "MainViewController.h"

@interface MainViewController ()

@end

@implementation MainViewController
@synthesize menuCollectionView;

- (void)viewDidLoad {
    [super viewDidLoad];
 
    [self.menuCollectionView registerClass:[InputCollectionViewCell class] forCellWithReuseIdentifier:[InputCollectionViewCell identifier]];

    menuCollectionView.delegate = self;
    menuCollectionView.dataSource = self;
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [InputCollectionViewCell dealloc];
}


- (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
    // Dequeue a reusable cell from the collection view.
    InputCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[InputCollectionViewCell identifier] forIndexPath:indexPath];
     [cell addBorderAndShadow];

       // Configure the cell with data for the index path.
 //      MyData *data = self.myDataArray[indexPath.item];
    //   [cell configureWithData:data];

       // Return the configured cell.
       return cell;
}

enter image description here

HangarRash
  • 7,314
  • 5
  • 5
  • 32
  • 1
    Does this answer your question? [Xcode - How to fix 'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X" error?](https://stackoverflow.com/questions/3088059/xcode-how-to-fix-nsunknownkeyexception-reason-this-class-is-not-key-valu) – HangarRash Jun 08 '23 at 06:06
  • So, where is `brickWall` outlet? – Cy-4AH Jun 08 '23 at 09:12
  • 1
    You need to use `registerNib:` and remove all that `fromNib`, `loadFromNib` garbage. – Cy-4AH Jun 08 '23 at 09:20
  • No, my class is in the owner files, and the iboutlets that I connect don't work – Jael Ruvalcaba Jun 09 '23 at 03:21

0 Answers0