UITableViewCell subclass throwing an unrecognized selector sent to instance

86 views Asked by At

My UITableViewCell is giving a -[UITableViewCell nameTeam]: unrecognized selector sent to instance.

I created a PlayerStatsTableViewCell.xib with a UITableViewCell and UILabel. Set the Custom Class to "PlayerStatsTableViewCell" and its Table View Cell identifier to "playerStats"

PlayerStatsTableViewCell.h

@interface PlayerStatsTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *nameTeam;
@end

PlayerStatsTableViewCell.m

@implementation PlayerStatsTableViewCell
@synthesize nameTeam;

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

In my PlayerStatsTableViewController, cell.nameTeam is throwing the error

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    PlayerStatsTableViewCell *cell = (PlayerStatsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"playerStats"];
    [tableView registerNib:[UINib nibWithNibName:@"PlayerStatsTableViewCell" bundle:nil] forCellReuseIdentifier:@"playerStats"];

    cell.nameTeam.text = @"PLEASE";

    return cell;
}

PlayerStatsTableViewCell.xib showing Custom Class and Identifier

enter image description here enter image description here

The error message enter image description here

PlayerStatsTableViewController from Storyboard enter image description here

1

There are 1 answers

0
Yagnesh Dobariya On
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    PlayerStatsTableViewCell *cell = (PlayerStatsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"playerStats"];
    if (cell == nil) {
          NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"PlayerStatsTableViewCell" owner:self options:nil];
          cell = (PlayerStatsTableViewCell *)[nib objectAtIndex:0];
    }

    cell.nameTeam.text = @"PLEASE";

    return cell;
}