iphoneiosuitableview

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


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

Solution

  • If you are connecting the outlets from the file's owner, you should do different:

    1 - Define the class of the UITableViewCell to your TableCell class:

    enter image description here

    2 - Connect the outlets not from File's Owner, but from TableCell in the objects list:

    Connect the outlets