Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I've looked at almost all of the related questions about this here in stackoverflow and tried all their possible solutions but I still can't figure out why I get this error:

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

I'm trying to load a customized table view cell with the nibname: @"CustomCell". Its class is assigned to "CustomCell" (same class name as the nib name). Its file's owner is also set to the class which loads this cells - "ProductsTableViewControllerWithSearch". All the outlets in the nib are connected to the ones in CustomCell.m

Here's my code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellClassName = @"CustomCell";
    static NSString *CellIdentifier = @"Custom Items Cell";

    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {

      NSArray *topLevelItems =  [[UINib nibWithNibName:CellClassName bundle:[NSBundle mainBundle]] instantiateWithOwner:self options:nil];
        cell = [topLevelItems objectAtIndex:0];

    }
//... more irrelevant code here
}

Can somebody help me please. I've been working on this for more than 4 hours. Thanks a lot!

PS: I'm using ARC and am developing for iOS 5.

Here's my CustomCell.h.

#import <UIKit/UIKit.h>

@interface CustomCell : UITableViewCell{
    UILabel *textLabel;
    UILabel *detailTextLabel;
    UIButton *starButton;
}

@property (strong, nonatomic) IBOutlet UILabel *textLabel;
@property (strong, nonatomic) IBOutlet UILabel *detailTextLabel;
@property (strong, nonatomic) IBOutlet UIButton *starButton;

@end

There's nothing in my CustomCell.m

like image 945
acecapades Avatar asked Mar 15 '12 03:03

acecapades


2 Answers

This error occurs if you are linking up any thing that does not belongs to that view.

In this case, the solution is in Interface Builder

  1. First Change the File's Owner Identity Class to NSObject.
  2. Unlink every IBOutlet in File's Owner.
  3. Change the Identity Class of Your custom NIBs to the name of CustomTableViewCell class.
  4. Link all your IBOutlet here.

That's it.

like image 128
Black Tiger Avatar answered Oct 13 '22 19:10

Black Tiger


In Interface Builder you need to set the class of the cell to CustomCell and CustomCell needs to have a property title.

this class is not key value coding-compliant for the key …

Usually means that a property is not found on a class and Interface Builder is trying to use that property, resulting in a crash.

like image 25
JoePasq Avatar answered Oct 13 '22 19:10

JoePasq