I am getting this error:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x5a37750> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key destination.'
Following is the code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"ReservationCell";
ReservationCell *cell = (ReservationCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"ReservationCell" owner:nil options:nil];
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (ReservationCell *) currentObject;
break;
}
}
}
//cell.origin.text = [[data objectAtIndex:indexPath.row] origin];
//cell.destination.text = [[data objectAtIndex:indexPath.row] destination];
//cell.time_range.text = [[data objectAtIndex:indexPath.row] time_range];
return cell;
}
Here is the ReservationCell.h
#interface ReservationCell : UITableViewCell {
UILabel * origin;
UILabel * destination;
UILabel * time_range;
}
#property (nonatomic, retain) IBOutlet UILabel * origin;
#property (nonatomic, retain) IBOutlet UILabel * destination;
#property (nonatomic, retain) IBOutlet UILabel * time_range;
#end
Here's how I wired it up:
For someone, who already reached to this thread and not able to figure out the solution like me, here is the quick solution to this problem:
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.
Good Luck!!!
This problem happen when in the interface builder for the CustomCell nib, the File's Owner custom class is set to your CustomCell class.
File's owner custom class should be set always UITableViewCell.
Table view object custom class should be set to your CustomCell class.
Also you need to initialize it with Nib name of your tableview cell.
Example (NotificationCell is my custom cell class):
http://i42.tinypic.com/29pw0a8.png
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"ReservationCell"
owner:nil
options:nil];
Is setting the Files Owner to nil. So you can't wire any of your labels to that. Instead, make sure the class of the cell is ReservationCell and its outlets are connected to the labels.
My exception was 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key (and name label which I had on the CustomCell, I got this error only when I added something in CustomCell e.g. label)
Solution problem my friend gave me great advice add MyCustomCell.m add to the ProjectSettings -> Build Phases -> add MyCustomCell.m file
In my case I had added the interface for the cell to the header file but did not have an implementation in the .m file. Simply adding an empty implementation (as below) for the class to the .m file fixed the problem.
#implementation myTableViewCell
#end
Surprised this has not been listed as an answer as this has bitten me several times in the past. Hope this helps someone!
I had this problem when I had duplicated a prototype cell in storyboard and deleted one of the outlets in the cell. It left a reference to the outlet but not connected to anything. Right-click on the prototype cell and look for one of those yellow warning markers.
Related
I looked at the TableViewUpdates/TVAnimationGestures from Apple's WWDC 2010 code and am having trouble duplicating a UITableViewCell subclass. This is what I've done:
I created a new UITableViewCell subclass with some simple properties:
#interface TargetDetailTableViewCell : UITableViewCell
#property (nonatomic, retain) IBOutlet UILabel *DescriptionLabel;
#property (nonatomic, retain) IBOutlet UILabel *ValueLabel;
#property (nonatomic, retain) IBOutlet UIImageView *DotImageView;
In the .m, I just release memory. In IB, I change my class to TargetDetailTableViewCell for the UITableViewCell I just dragged into IB. I connect the outlets from the TargetDetailTableViewCell to the appropriate labels and image view.
In the class I want to use this:
#class TargetDetailTableViewCell;
//some properties
#property (nonatomic, assign) IBOutlet TargetDetailTableViewCell *TargetCell;
In the .m:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *TargetCellIdentifier = #"TargetDetailTableViewCellIdentifier";
TargetDetailTableViewCell *cell = (TargetDetailTableViewCell *)[tableView dequeueReusableCellWithIdentifier:TargetCellIdentifier];
if (cell == nil) {
UINib *nib = [UINib nibWithNibName:#"TargetDetailTableViewCell" bundle:nil];
[nib instantiateWithOwner:self options:nil];
cell = self.TargetCell;
self.TargetCell = nil;
}
// set some labels
return cell;
}
When I run it, I get the error: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
The only think I can see that is different between Apple's example and mine is that when I ctlr-click on the subclass of UITableViewCell in their IB, they have a File's Owner property set. I have no idea how they connected that outlet as it is declared as a property in the class they use the cell, but there is no physical IB connection they make. Can someone explain that to me or what I am doing wrong?
Also, if anyone can explain this, that would be great:
UINib *nib = [UINib nibWithNibName:#"TargetDetailTableViewCell" bundle:nil];
[nib instantiateWithOwner:self options:nil];
cell = self.TargetCell;
self.TargetCell = nil;
It seems like you create the nib and the owner of the nib that gets instantiated from memory is the class you are in or self (my viewcontroller). Then the last two lines confuse me. It's like you tell your cell to point to the newly created object, then you set the newly created object to nil. Which in my head I think, the cell now points to nil as well. Thanks.
You need to have an owner in your custom table view cell nib and that owner needs to be your TableViewDataSource class (i.e. the table view controller which implements the cellForRowAtIndexPath method and has the TargetCell outlet to the table cell).
You also need to connect this TargetCell outlet from the file owner (the TableViewController) to your custom table view.
The reason for this is that when you load the nib, with your table view controller as the owner, it will then set the outlet that you have (the TargetCell property) to point to the table view cell defined in your nib.
You then copy this reference to the cell method variable, configure it and return it. You assign the property to nil after copying it because you only needed it as a bootstrap to get a reference to the object in the nib for use in the cellForRowAtIndexPath method.
I am trying to use custom UITableViewCells defined in IB where there are referencing outlets. I have successfully used the techniques shown in several places in stackoverflow to load and use UITableViewClass when there is no referencing outlet, like below.
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"TheCellsClass" owner:nil options:nil];
I have a separate file called "TheCellsClass.xib", which has a single UITableViewCell defined with a single UILable called Alabel, "IBOutlet UILabel *Alabel;". If I connect the label to ALabel then I get this error
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x681b360> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Alabel.'
After searching here and the web I understand that this is caused by the fact that "owner:nil" does not define a class with this object:Alabel. I cannot use "owner:self" because that is the UITableViewController, and also does not define "Alabel".
I created a class called "TheCellsClass" as a sub class of "UITableViewCell" that does define Alabel, see below;
Then used:
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"TheCellsClass" owner:cell options:nil];
I still get the same error. So, can anyone point out the error of my ways? :-)
I only way I can think to fix this is to remove all referencing outlets and connect
them using code
Subclass header :
#import <UIKit/UIKit.h>
#interface TheCellsClass : UITableViewCell {
IBOutlet UILabel *Alabel;
}
#property (strong, nonatomic) UILabel *Alabel;
#end
Subclass body:
#import "TheCellsClass.h"
#implementation TheCellsClass
#synthesize Alabel;
#end
In the table view controller
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
I am using:
TheCellsClass* cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"TheCellsClass" owner:cell options:nil];
A zip of a sample project is here http://www.proaa.com/tryout.zip
Suggestions? Requests for more info?
Any help appreciated.
Geoff
Three things:
Remove TheCellClass from DetailViewController.xib
ALabel is linked to File's Owner in TheCellsClass - link it instead to TheCellsClass in the Objects section. Also consider renaming ALabel - it is standard to name instance variables beginning with a lowercase letter.
In MasterViewController, change
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"TheCellsClass" owner:cell options:nil];
to
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"TheCellsClass" owner:nil options:nil];
After these three changes, your custom TableViewCell appeared in the simulator. Also consider renaming TheCellsClass to something that hints at what it's subclassing, like MyCustomTableViewCell.
Without looking at your project, one thing comes to mind. If you have an instance of your custom cell in our nib, and then you have this label in that same nib, then the connection should be from the UILabel to the custom cell. You shouldn't be connecting it to file's owner, at least from the way you've described what you're trying to achieve.
Hope that helps.
I've created custom UITableCells a bunch of times and I've never run into this problem, so I'm hoping you can help me find the thing I've missed or messed up. When I run my app, the cells in my table view appear to be standard cells with Default style.
I have SettingsTableCell which is a subclass of UITableViewCell. I have a SettingsTableCell.xib which contains a UITableViewCell and inside that are a couple labels and a textfield. I've set the class type in the xib to be SettingsTableCell and the File's Owner of the xib to my table controller.
My SettingsTableController has an IBOutlet property named tableCell. My cellForRowAtIndexPath contains the following code to load my table view xib and assign it to my table controller's tableCell property:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"CellSettings";
SettingsTableCell *cell = (SettingsTableCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:#"SettingsTableCell" owner:self options:nil];
cell = self.tableCell;
self.tableCell = nil;
NSLog(#"cell=%#", cell);
}
// Configure the cell...
NSArray *sections = [self.settingsDictionary objectForKey:KEY_GROUPS];
NSDictionary *sectionInfo = [sections objectAtIndex:[indexPath section]];
NSArray *itemsInSection = [sectionInfo objectForKey:KEY_FIELDS];
NSDictionary *item = [itemsInSection objectAtIndex:[indexPath row]];
cell.textLabel.text = [item objectForKey:KEY_LABEL_NAME];
cell.labelName.text = [item objectForKey:KEY_LABEL_NAME];
cell.labelUnitsType.text = [item objectForKey:KEY_LABEL_UNITS];
return cell;
}
This is what my xib set up looks like in IB:
When I run my app, the table displays as if all of the cells are standard Default style cells though:
The seriously weird part is though... if I tap on the area of the cell where the textfield SHOULD be, the keyboard does come up! The textfield isn't visible, there's no cursor or anything like that... but it does respond. The visible UILabel is obviously not the UILabel from my xib though because the label in my xib is right justified and the one showing in the app is left justified.
I'm incredibly confused about how this is happening. Any help is appreciated.
EDIT: Here is the code for my SettingsTableCell class:
#interface SettingsTableCell : UITableViewCell {
UILabel *labelName;
UILabel *labelUnitsType;
UITextField *field;
}
#property (nonatomic, retain) IBOutlet UILabel *labelName;
#property (nonatomic, retain) IBOutlet UILabel *labelUnitsType;
#property (nonatomic, retain) IBOutlet UITextField *field;
#end
#import "SettingsTableCell.h"
#implementation SettingsTableCell
#synthesize labelName;
#synthesize labelUnitsType;
#synthesize field;
- (void)dealloc {
[labelName release];
labelName = nil;
[labelUnitsType release];
labelUnitsType = nil;
[field release];
field = nil;
[super dealloc];
}
#end
I don't know why, but I do know that strange things happen while saving the cell in instance variables.
Have you tried loading the cell directly in cellForRowAtIndexPath?
if (cell == nil) {
topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"MyNibName" owner:nil options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[UITableViewCell class]]) {
cell = currentObject;
break;
}
}
}
Your complete code for cellForRowAtIndexPath and SettingsTableCell.h/m would be of help.
My first thought (probably wrong!) is that this is a z order issue and that the cells default label is being displayed on top of your text editing control. Hence not being able to see it. I'd guess that it still responds because the touch is being passed through by the label.
Just a guess :-)
Attempting to implement a "Simple" a CustomCell,
I have a normal tableViewController that renders fine using the normal "default" methods,
but I need to implement a Custom cell with some UILabel's and a UIImage.
So I created the CustomCell.h, CustomCell.m, CustomCell.xib
The .H
#interface CustomCell : UITableViewCell <UITextViewDelegate>
{
IBOutlet UIImageView *image;
IBOutlet UILabel *name;
IBOutlet UILabel *date;
IBOutlet UILabel *comment;
}
#property (retain,nonatomic) IBOutlet UIImageView *image;
#property (retain,nonatomic) IBOutlet UILabel *name;
#property (retain,nonatomic) IBOutlet UILabel *date;
#property (retain,nonatomic) IBOutlet UILabel *comment;
and .M
#implementation CustomCell
#synthesize image;
#synthesize name;
#synthesize date;
#synthesize comment;
#pragma mark -
#pragma mark View lifecycle
- (id) initWithController: (Controller *) ctnlr
{
ControllerPointer = ctnlr;
return(self);
}
- (void) SetImage:(UIImageView*)Image
{
image = Image;
}
- (void) SetName:(NSString*)Name
{
[Name retain];
[name.text release];
name.text = Name;
}
- (void) SetDate:(NSString*)Date
{
[Date retain];
[date.text release];
date.text = Date;
}
- (void) SetComment:(NSString*)Comment
{
[Comment retain];
[comment.text release];
comment.text = Comment;
}
anyway, when I attempt to create these customcells in cellForRowAtIndexPath (as one would expect might be implemented) I am left with only a blank screen. So obviously I am missing something big... When I created the .XIB file with "Interface Builder" I made sure to connect the "Referencing Outlets" to the appropriate labels and images.
So following the implied logic of the way the Xcode framework appears to work,
I followed the same reasoning (for lack of an exact example) No worky...
Anyway, if there are any IPhone geeks that would like to enlighten me...
(yes, there are no "[something release]" calls, I am not even sure if anything needed to be alloc'd. Please tell me there's just a couple calls I am leaving out, it can't be too much more than something simple like this Right...?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[[NSBundle mainBundle] loadNibNamed:#"CustomCell" owner:self options:nil] lastObject];
}
NSUInteger row = [indexPath row];
SnsObject *sObj = [SnsArray objectAtIndex:row];
[cell SetName:[sObj getUserName]];
NSUInteger row = [indexPath row];
SnsObject *sObj = [SnsArray objectAtIndex:row];
cell.name = [[UILabel alloc]init];
cell.name.text = [sObj getUserName];
cell.date = [[UILabel alloc]init];
cell.date.text = [sObj getDateTime];
cell.comment = [[UILabel alloc]init];
cell.comment.text = [sObj getCommentText];
cell.image = [[UIImageView alloc]init];
cell.image.image = [sObj getImageUrl];
return(cell)
}
Thanks in Advance!
There are other issues with the code beyond what mrcrowl mentioned about now needing to "alloc-init" the outlets. In particular, this line:
cell = [[[NSBundle mainBundle] loadNibNamed:#"CustomCell" owner:self options:nil] lastObject];
This is not the typical idiom used to load a custom tableview cell from a .xib. First of all, you pass "owner:self", which means you want to hook up the outlet objects in the .xib file with outlet members in your tableviewcontroller object, probably not what you intended.
Second, you're relying on the order of objects returned from loadNibNamed:owner:options:, which while it may work today, may not work tomorrow, or on a new release of iOS.
Instead, the usual idiom is to declare an outlet for the entire tableviewcell in your tableviewcontroller:
(in the .h file):
...
UITableViewCell *tvCell;
...
#property (nonatomic, retain) IBOutlet UITableViewCell *tvCell;
Then in place of your line, you have this:
[[NSBundle mainBundle] loadNibNamed:#"NewsArchiveTitleTvCell" owner:self options:nil];
cell = tvCell;
self.tvCell = nil;
Normally this isn't done with subclassing, notice how I didn't declare the class as CustomCell, but as a vanilla UITableViewCell. So how to you get at those pesky subviews so you can configure them? Using tags is the normal way:
...
#define kMyKewlLabelTag 1
...
UILabel *kewlLabel = (UILabel *) [cell viewWithTag:kMyKewlLabelTag];
kewlLabel.text = [NSString stringWithFormat:#"Hi there from row %d!", indexPath.row];
...
EDIT:
edit: here's a bit more detail, comments are too short to address the "what's going on here?" question. Here's an excerpt from one of my apps that loads the UITableViewCell from a .xib:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"MyShoppingCartTvCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:#"ShoppingCartTvCell" owner:self options:nil];
cell = tvCell;
self.tvCell = nil;
}
...
// (insert code to grab model data for this row)
...
UILabel *nameLabel = (UILabel *) [cell viewWithTag:1];
nameLabel.text = itemNameStr;
UILabel *countLabel = (UILabel *) [cell viewWithTag:2];
countLabel.text = [NSString stringWithFormat:#"%d", itemCount];
UIImageView *iv = (UIImageView *) [cell viewWithTag:3];
...
Here's what's going on here:
There is no custom UITableViewCell subclass, there is only a .xib file named "ShoppingCartTvCell.xib" containing a UITableViewCell, and UI elements placed inside the UITableViewCell. UI elements whose data must change per row are assigned a unique tag (the tag field is in the CMD-1 Attributes Inspector in IB) so that your code can get a handle to those objects to change them (customize labels, images, etc). Make sure you don't use "0" since all elements by default have a 0 tag. Also, make sure the Identifier field of the UITableViewCell in CMD-1 Attributes Inspector is the CellIdentifier string.
The File's Owner of the .xib file is your table view controller where you want to display the cell. More precisely, it can be any class containing a IBOutlet UITableViewCell *tvCell; member. It is an instance of this class that you pass in as owner to loadNibNamed:owner:options:. As long as the value of the linked outlet is nil in the owner, when you call loadNibNamed:owner:options, the outlet of the owner is filled in with the object from the .xib (as long as the connection was made in the .xib in IB). Understanding that is a magic moment in Apple programming that opens whole new vistas to you :).
You must set self.tvCell = nil; to prepare for the next cellForRowAtIndexPath that needs to load from the .xib. I also sometimes set to nil before loadNibNamed:owner:options:, I think that's a bit safer actually.
Here's how you go about loading your UITableViewCells from a .xib:
In xcode, add an IBOutlet UITableViewCell *tvCell; to your UITableViewController class (including property declaration if you like)
In your xcode project, create a New File, User Interface, Empty Xib. Open this .xib in IB
In IB, drag a TableViewCell from the Library into your empty .xib file under First Responder
Click File's Owner, CMD-4 (Identify Inspector), and under Class select the class containing the IBOutlet UITableViewCell *tvCell that you added (probably your UITableViewController subclass, the class where you're manipulating your table).
Control-drag from File's owner to the UITableViewCell, and select the outlet you want to hook up. This is the field that will hold the newly-loaded-from-xib UITableViewCell when you call loadNibNamed:owner:options with an instance of File's Owner as the "owner" parameter.
Add UI elements into the UITableViewCell (make sure they're inside the UITableViewCell hierarchy). Any elements that you want to customize per-row require a unique tag value.
follow the recipe I gave above in cellForRowAtIndexPath
Have a magic moment where you start to understand how .xib files and File's Owner objects really work together, and start creating lots of cool UITableViewCells and other custom view objects in IB because it's really easy and way better than creating them in code (IMNSHO).
When you load a UITableViewCell from a .xib, you shouldn't need to create the controls manually.
For example, this kind of thing is unnecessary:
cell.name = [[UILabel alloc]init];
This will replace the label loaded from your xib with a new label that has a zero frame -- that is, the new label will be located at 0,0 and will have no width or height. Hence, no worky.
Assuming you have the xib hooked up correctly to CustomCell's IBOutlets, they controls you are seeking should already be there.
P.S. Forgive me if I am reading too much into your method name, but I don't think this line will work either, because the .image property expects a UIImage:
cell.image.image = [sObj getImageUrl];
Ok... Thanks all for the good input, but sometimes the simplest answer is not only the most eloquent, it's the best... Here's what I found to work,, keeping it as simple as possible, without changing a thing outside of one function.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"CustomCellIdentifier";
CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"CustomCell" owner:self options:nil];
for(id oneObject in nib)
{
if([oneObject isKindOfClass:[CustomCell class]])
{
cell = (CustomCell*)oneObject;
}
}
}
NSUInteger row = [indexPath row];
printf("MainMessageBoard.m cellForRowAtIndexPath = [%i]\n",row);
SnsObject *sObj = [SnsArray objectAtIndex:row];
cell.Name.text = [sObj getUserName];
cell.Date.text = [sObj getDateTime];
cell.Comment.text = [sObj getCommentText];
cell.Image.image = [self resizeImage: [self imageFromURLString: [sObj getImageUrl]] scaledToSize:CGSizeMake(32.0f, 32.0f)];
cell.CommentCount.text = [NSString stringWithFormat:#"(%d)", [sObj getCommentCount]];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
return(cell);
}
This question already has answers here:
Xcode - How to fix 'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X" error?
(79 answers)
Closed 7 years ago.
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 :
AlertCell.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#interface AlertCell : UITableViewCell {
IBOutlet UILabel *actionText;
}
#property (retain, nonatomic) UILabel *actionText;
#end
And
AlertCell.m
#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:
Instantiate a new cell in your -cellForRowAtIndexPath:(NSIndexPath *)indexPath implementation, and pass that new cell as the owner (but i'd guess that this isn't the best solution for you)
Or, and I'd suggest this is the better solution, change the binding of actionText in your nib file to the Alert Cell and not the file's owner (You have File's Owner and an Alert Cell - bind the UILabel to the actionText outlet of the Alert Cell, and not the File's owner, which is what's being done at present) - I suspect this is what you want. With that in mind file's owner can become an NSObject again.
------- 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:
Name your files after your class (upper case the first character of the filename).
Prefix your class names; two uppercase characters, typically your initials (i'd name it DWAlertCell, for example).
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
Go to the Xib file, and right click (Ctrl+Mouse Click) on each UI
element to see its associations.
In its referencing outlets section, you will be able to locate the
erroneous association.
Remove that association
Clean the solution and build folder
Reset Simulator
Rebuild and run the project.
check UIControl Referencing OutLet Property Name from nib/StoryBoard File
Make sure select cell to put custom class not File's Owner to add custom class
on right side top
and if You have done so, Before you make any changes remove outlet connection and then remove custom class from File's Owner and add Class to Cell view
Maybe it helps:
Indentity Inspector when you have selected file's owner - UITableViewCell,
when you have selected the cell inside Objects Your custom cell nane
After 2 hours on this, I realized that i forgot to
#synthesize tableView = _tableView;
Hope it helps.
Mário
#import <UIKit/UIKit.h>
#interface ReceptionDetailCell : UITableViewCell
#property (weak, nonatomic) IBOutlet UILabel *productName;
#property (weak, nonatomic) IBOutlet UILabel *billType;
#property (weak, nonatomic) IBOutlet UILabel *bookTime;
#property (weak, nonatomic) IBOutlet UILabel *doctorName;
#property (weak, nonatomic) IBOutlet UILabel *downBillManName;
#end
Checkout out the Cell code and storyboard setting, whether they are all exist, maybe you have changed their names.