3

I'm getting a crash when running on an iOS6 device but NOT an iOS 7 device. I have a custom UITableViewCell with a xib LanguageCell.xib. It has 2 labels, a button, and a view. I have a class LanguageCell where I have 4 IBOutlets:

@interface LanguageCell : UITableViewCell

@property (strong, nonatomic) IBOutlet UILabel *titleLbl;
@property (strong, nonatomic) IBOutlet UIButton *buyButton;
@property (strong, nonatomic) IBOutlet UILabel *saleLbl;
@property (strong, nonatomic) IBOutlet UIView *separatorLine;

I have connected all 4 views to their properties so the connections pane looks like this:

enter image description here

When I run the app, I get a crash when loading this table:

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

Why am I getting this problem on iOS6 but not iOS7?

EDIT: I should add that the Custom Class is set properly on the xib

enter image description here

EDIT 2: When I clear all the IB connections and run the code, the line if ([currentObject isKindOfClass:[LanguageCell class]]) returns false when it should be true, thus cell remains nil

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"cell";
    LanguageCell *cell = (LanguageCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"LanguageCell" owner:nil options:nil];
        for (id currentObject in topLevelObjects)
        {
            if ([currentObject isKindOfClass:[LanguageCell class]])
            {
                cell = (LanguageCell *)currentObject;
                break;
            }
        }
    }

I use the same exact code for 3 other tables in my app and it works just fine. I don't understand why this one is giving me problems.

Kevin_TA
  • 4,575
  • 13
  • 48
  • 77
  • 1
    Did you try cleaning the project? `Shift+CMD+K` – hgwhittle Feb 26 '14 at 21:49
  • Yup. Clean, Clean Build Folder, Delete Derived Data, close Xcode, delete app from phone, etc. Nothing has worked :( – Kevin_TA Feb 26 '14 at 21:58
  • The storyboard can get corrupted sometimes, try clearing the connection in IB, saving, and recreating it. – David Berry Feb 26 '14 at 22:01
  • I'm not using a storyboard. Does the same apply? FWIW, I have cleared and recreated the connection a few times. I've also completely recreated the XIB. No luck. – Kevin_TA Feb 26 '14 at 22:08
  • 1
    How are you generating cells? Could you show your `cellForItemAtIndexPath` function? – Shizam Feb 26 '14 at 22:49
  • Is your xib set up for iOS 6 compatibility? – Eiko Feb 26 '14 at 23:05
  • I assume you mean the 'Builds for' field in the 'File inspector'? That is set for deployment target (6.0). – Kevin_TA Feb 26 '14 at 23:10
  • 1
    Having looked at your `cellForItemAtIndexPath` is the 'Reuse Identifier' field in IB correctly set to "cell"? Also, side note, I think you'll find using `registerNib:forCellWithReuseIdentifier` when using xibs for your cells is a better solution. You won't have to do all that `NSBundle` stuff, it'll just automatically use the correct xib for you – Shizam Feb 26 '14 at 23:23
  • It's not set to `cell` actually, but none of my other `UITableViewCell` subclasses are either and they work just fine... I suppose I could try changing that? Would you mind providing code on generating the cell using the method you stated? – Kevin_TA Feb 26 '14 at 23:54
  • 1
    Can it help you http://stackoverflow.com/questions/3088059/this-class-is-not-key-value-coding-compliant-for-the-key ? – Lanorkin Feb 27 '14 at 15:27
  • You should definitely use the reuseIdentifier correctly, it should be set to something unique for each cell, otherwise you might end up with the system re-using a cell which doesn't contain your `buyButton` – Sammio2 Mar 13 '14 at 20:10

1 Answers1

3

I had exactly the same problem. This normally just happens if you connected an element inside the Interface Builder with a method which doesn't exist anymore.

I also used the same class name. After changing the name, everything worked for me even on iOS 6.0.

Alex Cio
  • 6,014
  • 5
  • 44
  • 74