UITableViewCell子类抛出一个发送到实例的无法识别的选择器

时间:2015-06-25 05:13:42

标签: uitableview xib unrecognized-selector

我的UITableViewCell给出了一个 - [UITableViewCell nameTeam]:发送到实例的无法识别的选择器。

我使用UITableViewCell和UILabel创建了一个PlayerStatsTableViewCell.xib。将自定义类设置为“PlayerStatsTableViewCell”,将其表视图单元格标识符设置为“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
}

在我的PlayerStatsTableViewController中,cell.nameTeam抛出错误

- (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显示自定义类和标识符

enter image description here enter image description here

错误消息 enter image description here

来自Storyboard的

PlayerStatsTableViewController enter image description here

1 个答案:

答案 0 :(得分:0)

- (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;
}