9
votes

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

4
What is CustomCell a subclass of? - JoePasq

4 Answers

13
votes

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.

9
votes

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.

6
votes

I'm presuming that you get this error when your cell is loaded from the NIB at runtime. (If instead it's breaking on some line of code you've written, for God's sake delete that line of code!)

Go into your custom cell's XIB view, ctrl-click on "File's owner" and unlink whatever connection you've got in there called 'title'. If you're feeling spunky, unlink everything, then relink the stuff you want. See if that clears it up. If not I'll be here for a few hours.

0
votes

For my case of XCode6.0.1 ,I clean the project and everything runs smoothly