Custom UITableViewCell gives me: this class is not key value coding-compliant

Viewed 15782

First of all, this discussion did not solve my problem.

Custom UITableViewCell subclass: This class is not a key value coding-compliant

Setup:

I have an array of Person objects in MainViewController. Want to show the objects in an UITableView in AllContactsViewController.

Problem:

All works as expected when use the default UITableViewCell. When I use my custom TableCell I get an error pointing to that this class is not key value coding-compliant.

This error occurs right after I connect ANY of my three outlets in IB with my TableCell Class.

Note:

TableCell has three properties: a name & email label + imageView.

Hope you can help.

TableCell.h

#import <UIKit/UIKit.h>

@interface TableCell : UITableViewCell

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *emailLabel;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

TableCell.m

#import "TableCell.h"

@implementation TableCell
@synthesize nameLabel, imageView, emailLabel;

AllContactsViewController.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdent = @"TableCell";

    TableCell *cell = (TableCell *)[tableView dequeueReusableCellWithIdentifier:cellIdent];

    if (cell == nil) {

        NSArray *array = [[NSBundle mainBundle]loadNibNamed:@"TableCell" owner:self options:nil];
        cell = [array objectAtIndex:0];
    }

    NSString *firstAndLastnameString =
    [NSString stringWithFormat:@"%@ %@",
     [(NewContact *)[self.allContactsArray objectAtIndex:[indexPath row]] firstName],
     [(NewContact *)[self.allContactsArray objectAtIndex:[indexPath row]] lastName]];

    cell.nameLabel.text = firstAndLastnameString;

    cell.emailLabel.text =
    [(NewContact *)[self.allContactsArray objectAtIndex:[indexPath row]] eMail];

    cell.imageView.image =
    [(NewContact *)[self.allContactsArray objectAtIndex:[indexPath row]] contactPicture];

    return cell;
}

UPDATE:

Maybe a screenshot will help from IB.

enter image description here

Added full AllContactsViewController.h

#import <UIKit/UIKit.h>
#import "VCDelegate.h"
#import "TableCell.h"

@interface AllContactsViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>

@property (weak, nonatomic) id <VCDelegate>delegate;

@property (weak, nonatomic) IBOutlet UITableView *allContactsTableView;

@property (strong, nonatomic) NSMutableArray *allContactsArray;

@property (assign) int currentArrayIndexNumber;

- (IBAction)closeBtnTapped:(id)sender;

@end
6 Answers

Everything was done right on my project and still received when try to use custom cell with its properties. Here how I solved mine.

CustomUITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomUITableViewCell" forIndexPath:indexPath];

What actually hit me is simply remove the CustomUITableViewCell Class from the custom cell's "Identity Inspector" and re-enter it.. you will see a changes

  1. Module value
  2. Inherit Module From Target

Let them be the value which automatically comes up... don't try to inherit it or change the inheritance or the Module value...

enter image description here

Had the same issue using Xcode 12. It worked by simply retyping the class on the Identity Inspector. Seems like a bug.

Related