Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom UITableViewCell erroring

I am trying to build a custom table view using a cell that I built in IB. I am getting a strange error:

<BroadcastViewController 0x4b4f5f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key postText.

Everything is wired up correctly in IB to the cell controller. Not really sure why this is happening.

This is what my cellForRowAtIndexPath looks like:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

//Get the folder object of interest
Broadcast *messageAtIndex = [self.messages objectAtIndex:indexPath.row] ;

static NSString *CellIdentifier = @"BroadcastTableViewCell";
static NSString *CellNib = @"BroadcastTableViewCell";

BroadcastTableViewCell *cell = (BroadcastTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
   //ERRORING ON THIS LINE...
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:self options:nil];
    cell = (BroadcastTableViewCell *)[nib objectAtIndex:0];
}


cell.postText.text = messageAtIndex.replyText;
cell.authorName.text = messageAtIndex.postCreatorFirstName;
cell.postDate.text = messageAtIndex.creationDate;

return cell;

}

Anyone seen this kind of error before? Let me know if you need any more information...

like image 568
gabaum10 Avatar asked Oct 15 '10 14:10

gabaum10


3 Answers

What is really strange is that it complains that the class BroadcastViewController is not KVC compliant to postText.

As far as I can see, postText is a label in your cell, so the IBOutlet for this should be in the BroadcastTableViewCell class. So check out where you've linked the postText label in IB. Also, it can be that you had an IBOutlet in your view controller for this label, you've removed it but you forgot to delete the link in IB. Anyway, there somewhere is your problem. The fact that you have the error on that line is just because it's there you load your NIB, it doesn't have anything to do with the cell itself or with the owner.

like image 106
Stelian Iancu Avatar answered Nov 04 '22 02:11

Stelian Iancu


Might has something to do with dequeueReusableCellWithIdentifier returning an UITableViewCell*.

I normaly do this:

UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier...
CustomCell* acell = (CustomCell*)cell; 

Set the owner to nil.

NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:nil options:nil]; 
like image 1
Sander Avatar answered Nov 04 '22 00:11

Sander


Ok figured it out. The connections in IB were indeed incorrect. I had them linked to the file's owner as opposed to the actual objects. I am going to give this too Stelian because he directed me to check out the nib. Thanks for all your help!

like image 1
gabaum10 Avatar answered Nov 04 '22 00:11

gabaum10