1

I have a table with two custom cells that crash when try to dequeue.

Here is the code :

int row = indexPath.row;

static NSString *CellIdentifier;
UITableViewCell* cell;
PoetCell * poetCell;
PoemsCell * poemsCell;

if(row == 0) {

    CellIdentifier = @"PoetCell";

} else {

    CellIdentifier = @"poemsCell";        
}

if(row == 0) {

    poetCell= [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    poetCell.image.image=[UIImage imageWithData:imageData];

    if([imageData length]==0){

        poetCell.image.hidden=TRUE;
        poetCell.Name.frame=CGRectMake(124, poetCell.Name.frame.origin.y, poetCell.Name.frame.size.width, poetCell.Name.frame.size.height);

    } else {

        poetCell.Name.frame=CGRectMake(38, poetCell.Name.frame.origin.y, poetCell.Name.frame.size.width, poetCell.Name.frame.size.height);

    }

    poetCell.desc.text=pdesc;
    poetCell.Name.text=pName;

} else {

        poemsCell= [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if([poemsNames count]) {
            poemsCell.poemText.text=[poemsNames objectAtIndex:row-1];
        }
}

It gives error on the line :

poetCell= [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];

which say

[UITableViewCell setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Name.

I know this error comes when there's a bad link in the nib.. But that's not the case I believe it is in the code.. So can any one get what the problem is ?

EDITed

i think the whole problem is with the initializing of poetCell and poemsCell which is that's the code

#import <UIKit/UIKit.h>

@interface PoetCell : UITableViewCell
{
    IBOutlet UILabel*Name;
    IBOutlet UILabel*desc;
    IBOutlet UIImageView*image;
}
@property(nonatomic,retain)IBOutlet UILabel*Name;
@property(nonatomic,retain)IBOutlet UILabel*desc;
@property(nonatomic,retain)IBOutlet UIImageView*image;

@end

#import "PoetCell.h"

@implementation PoetCell
@synthesize Name,desc,image;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}

the other cell is just the same

Mohamed Emad Hegab
  • 2,665
  • 6
  • 39
  • 64

3 Answers3

0

you might have problem in the code ! it is if the array does not have the requested index?

just make your check like this

    if([poemsNames count] > row  ){
        poemsCell.poemText.text=[poemsNames objectAtIndex:row-1];
    } 
Omar Freewan
  • 2,678
  • 4
  • 25
  • 49
0

You are using poetCell.Name. Can you make sure your custom cell has a "Name" property (in your custom cell's .h/.m) ? I think the problem comes from here.

By the way, if your custom cell does have this property, you should change it to name instead of Name. Variables with an upper case letter at the beginning is for classes names. Variables should always start with a lower case letter.

You should post your custom cell's code too.


EDIT :

As seen here : Class is not key value coding-compliant

In interface builder you linked your IBOutlets from File's Owner when you should link them from the cell view.

Can you check that ?

Community
  • 1
  • 1
rdurand
  • 7,342
  • 3
  • 39
  • 72
  • Can you give us the code of your custom cell ? How can you be sure it comes from the line *poetCell= [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];* ? Can you place a breakpoint on the next line to see if you reach it ? – rdurand Nov 13 '12 at 11:04
  • lol, just checking :) Can you check in your nib if there are no "dead" links ? Like an old label you may have linked then deleted ? I can't see why you'd get this error with this line.. – rdurand Nov 13 '12 at 13:02
  • Did you set your table view cell's class to your custom class in IB ? – rdurand Nov 13 '12 at 15:32
  • And you checked "dead" links ? – rdurand Nov 13 '12 at 15:39
  • i've made a whole new viewController in the storyboard and without wiring any iboutlet it gives Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell Name]: unrecognized selector sent to instance 0x9ce7280' – Mohamed Emad Hegab Nov 13 '12 at 15:41
  • That's because you have to link your IBOutlets to your .h file. Set the cell's class, and link to the existing IBOutlets in your cell's .h file. – rdurand Nov 13 '12 at 15:44
0

assuming you're targeting iOS5+, have you included something like the following in viewDidLoad:

[self.tableView registerNib:[UINib nibWithNibName:kStandardCellIdentifier bundle:nil] forCellReuseIdentifier:(NSString *)]
sberley
  • 2,238
  • 1
  • 16
  • 12