I know the meaning of this error, but I'm really struggling with it, and I need someone's help :
2010-09-21 15:03:11.562 Stocks[5605:207] *** Terminating app due to uncaught
exception 'NSUnknownKeyException', reason: '[<NSObject 0x499fb20>
setValue:forUndefinedKey:]: this class is not key value coding-compliant
for the key actionText.'
There is my code here :
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface AlertCell : UITableViewCell {
IBOutlet UILabel *actionText;
}
@property (retain, nonatomic) UILabel *actionText;
@end
And
@implementation AlertCell
@synthesize actionText;
- (void)dealloc {
[actionText release];
[super dealloc];
}
@end
The problem happens just there :
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
AlertCell *cell =
(AlertCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AlertCell"
owner:nil
options:nil];
for (id oneObject in nib) {
if ([oneObject isKindOfClass:[UITableViewCell class]]) {
cell = (AlertCell *)oneObject;
break;
}
}
}
cell.actionText.text = [arrayAlert objectAtIndex:indexPath.row];
return cell;
}
On this line :
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AlertCell"
owner:nil
options:nil];
As asked, here is my header for the TableViewCOntroller :
#import <UIKit/UIKit.h>
@interface AlertesViewController : UITableViewController {
NSMutableArray *arrayAlert;
}
And you can see my XIB file (as XML): http://pastebin.com/FDVzLYZu
@end
Can anyone help me ? Thanks a lot !
you probably based your code on a web tutorial such as the one at http://www.e-string.com/content/custom-uitableviewcells-interface-builder or http://www.icodeblog.com/2009/05/24/custom-uitableviewcell-using-interface-builder/
Your problem (and I'm 99% sure this is where you tripped up, I just made the same mistake) is that in interface builder you linked your IBOutlets from File's Owner when you should link them from the cell view. This is why you are getting the errors.
There are a couple of options to resolve this - i'll let you decide which is the most appropriate.
The reason it's failing is because the owner is being passed as nil. You're binding the actionText outlet to the file's owner in IB, but then when loading the nib, the owner is nil. I'd guess that when loading with a nil owner behind the scenes an NSObject is used, which is why you're getting the key/value error.
My previous advice to pass the cell as the owner would also fail as I didn't know how the Nib is constructed; the cell is nil as you've yet to create it (and dequeue is passing nil back, so even pass cell as the owner is still essentially passing nil).
Two options:
------- Original answer kept below as the file's owner class is also a common cause for this error -------
It suggests that you've 'instantiated' an AlertCell in InterfaceBuilder, and you're binding something to actiontext, but the class isn't set to AlertCell, it's still NSObject?
Take a look at the class text box on the identify tab of the tool palette for that object in Interface Builder. The class should be AlertCell, but i'd guess it's still set to NSObject.
As an aside, and feel free to ignore this advice, but there are a couple of extra things i'd encourage you to do, purely from an Objective C expectations/conventions point of view:
I had the same problem, and I could not find the mentioned variable/element in any file. I followed the following steps.
Environment: Xcode 6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With