views:

3813

answers:

5

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 line 4 (below) of my code in the cellForRowAtIndexPath method

1- static NSString *CellIdentifier = @"Cell";

2- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
3- if (cell == nil) {
4- [[NSBundle mainBundle] loadNibNamed:@"SubjectCell" owner:self options:NULL];
5- cell = customSubjectCell;
6- }

What I find weird is that when I restore my whole project from Time Machine from a couple days ago, (when it was working) and I get the same error! I have tried this on two devices and the simulator, but all get the same error. Another issue is the fact that I have no clue what the exception means. If you need more code to help me with my dilemma, or have any questions, just ask. Also, I downloaded the new (today's) SDK, and I think that may have caused this, even though It was working with the New Xcode + SDK before I made changes to my app today.


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.

+6  A: 

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.

VeryVito
+1  A: 

I am also having this problem. I think it's maybe a bug of some type in the 3.2 Beta SDK as UITableViewCellContentView isn't even a real thing as far as I can tell.

CaptPhunkosis
+23  A: 

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
Slim
THANK YOU FOR FINDING THIS
ckrames1234
It just works! thanks so much.
Jirapong
Thank you so much! It was starting to drive me crazy!! (there's a "@end" missing at the end of the .h file though)
Supernico
Thanks a ton! This works! but why is it breaking existing projects?
Mugunth Kumar
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.
Squeegy
If you need to ship code for SDK 3.0 but can't because of above bug, what do you do?
4thSpace
+1 for 4th space comment
mga
+1 for a great answer its still relevant
hib
A: 

This workaround also worked for me, but I had to combine it with a rebuild of the .xib file in question.

reid
A: 

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