15

In my app, I use a custom NIB to load my UITableViewCells. The NIB's File's Owner is set so the class is my View Controller. I then Link the UITableViewCell to the IBOutlet I put in the header file. It was all working fine, until all of the sudden it stopped working, and gets this error:

uncaught exception 'NSInvalidUnarchiveOperationException', reason: '*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (UITableViewCellContentView)'

I have traced this exception to [NSBundle loadNibNamed:owner:options:]

static NSString *CellIdentifier = @"SubjectCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"SubjectCell" owner:self options:NULL];
cell = customSubjectCell;

I have tried this on two devices and the simulator, but all get the same error. I downloaded the new SDK today, and I think that may have caused this.


PLEASE NOTE:

This question is outdated, and the fix below was a temporary fix. Apple has fixed its SDK, so if you have the newest version of the SDK this does not apply to you.

conradev
  • 1,074
  • 1
  • 14
  • 31

3 Answers3

26

Found solution in dev forums

Create this files:

UITableViewCellContentView.h

#import <UIKit/UIKit.h>
@interface UITableViewCellContentView : UIView {
}
@end

UITableViewCellContentView.m

#include "UITableViewCellContentView.h"
@implementation UITableViewCellContentView

+ (id)alloc {
    return [UIView alloc];
}

+ (id)allocWithZone:(NSZone *)zone {
    return [UIView allocWithZone:zone];
}

@end
Taras Kalapun
  • 1,761
  • 15
  • 19
  • Thank you so much! It was starting to drive me crazy!! (there's a "@end" missing at the end of the .h file though) – nmondollot Jan 29 '10 at 11:10
  • Thanks a ton! This works! but why is it breaking existing projects? – Mugunth Jan 30 '10 at 11:38
  • 2
    WANING: Do not use this in shipping apps. It's a private class that Apple will likely not want you monkeying with. This is a known bug in 3.2 SDK which will get fixed. It's best not to install beta SDKs over your current one. Install to a different location so you can play around, but reserve your current SDK for work that needs to ship today. – Alex Wayne Feb 02 '10 at 21:46
  • If you need to ship code for SDK 3.0 but can't because of above bug, what do you do? – 4thSpace Feb 03 '10 at 18:56
7

Uh oh. I'm having the same issue... Also using today's new SDK (01/28/2010). Can't say for sure whether the code was working before, because I just added it AFTER updating to the new SDK.

Anybody else seeing this issue now? Any solutions?

Update: I just switched the simulator to SDK 3.2 (from 3.12), and whattaya know... it's working now (in the iPhone and iPad simulator). However, it doesn't work when compiling using SDK 3.12.

My guess is that IB is saving the XIB in a new format for 3.2 perhaps? Anybody know how to force it to save in the old (3.12) format? This definitely feels like a bug, as it's breaking previously working code.

Mike Fahy
  • 5,487
  • 4
  • 24
  • 28
1

I had the same thing. Installed 3.2 beta from 3.1.2 and had this error.

In the end this fixed it: Rebuild against Simulator 3.1 and I got a working build in the simulator. After this, builds against Simulator 3.1.2 work.

Megasaur
  • 626
  • 8
  • 20