gdubs
gdubs

Reputation: 2754

custom uitableviewcell will not display label texts

And the value of the labels are null as well.

I'm not really sure what's going on.

These are my classes/codes

@interface CustomEventCell : UITableViewCell{

}

@property (nonatomic, weak) IBOutlet UILabel *participant1label;
@property (nonatomic, weak) IBOutlet UILabel *participant2label;
@property (nonatomic, weak) IBOutlet UILabel *status;

@end

Event model is

@interface Event : NSObject{
}
@property NSNumber *matchId;
@property NSString *participant1, *participant2,
-(id)init;
@end

this is the tableview that fills up the cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"EventCell";

    CustomEventCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(cell == nil)
    {
        cell = [[CustomEventCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // events is a NSMutableArray with Event instances
    Event *event = [events objectAtIndex:indexPath.row];

    cell.participant1label.text = event.participant1;

    return cell;
   }

Here's my setup

enter image description here enter image description here

enter image description here

enter image description here

I must be missing something as I have another uitableview and it populatees the custom without problems. I compared them and they're identical. I even tried going back to the regular label and it would fill that up but not this custom one.

EDIT:

Modified the wrong copied code.

Upvotes: 1

Views: 2441

Answers (1)

ericg
ericg

Reputation: 8742

I wrote a simple little test app attempting to replicate what you want to see working. I have made it available here using Storyboards. If you cannot figure it out from this, then perhaps you can take the test app and modify it so that it replicates the bad behavior you are seeing.

My best guess as to what might be going on is that when you initialize your cell, it is not connected to a view in a xib.

Try setting a breakpoint at:

cell.participant1label.text = event.participant1;

and verify that cell.participant1label is not nil by doing:

NSLog( @"cell.participant1label: %@", cell.participant1label );

I had a small bug in which none of my custom labels were showing up and cell.participant1label was nil. The cause was that I had not set the Identifier for the custom table view cell to 'EventCell'. So, I might suggest rechecking that and making sure the identifier really does match between your code and the XIB.

Upvotes: 1

Related Questions