发送到实例

时间:2015-10-29 01:43:03

标签: ios objective-c uitableview

所以我有一个带有3个UILabel的自定义UITableViewCell。其中每个文本都设置为label.text = @"something";。但是当我滚动过去(让我们说单元格0)然后向上滚动到它时,应用程序与-[__NSCFString setText:]: unrecognized selector sent to instance一起崩溃,并且我将文本设置为红色。此外,所有其他单元格(使用相同的可重复使用的单元格)都没有填充该标签。在UITableViewCell子类中,我将属性设置为strong

使用UITableView的类:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ChampionDetailSpellCell *cell = [tableView dequeueReusableCellWithIdentifier:@"championAbilityCell" forIndexPath:indexPath];
// Performance
cell.layer.rasterizationScale = [[UIScreen mainScreen] scale];
cell.layer.shouldRasterize = YES;

// Design
cell.backgroundColor = [UIColor clearColor];
cell.backgroundView = nil;

// Reset
cell.abilityIcon.image = nil;
cell.abilityNameLabel.text = nil;
cell.abilityCost.text = nil;
cell.abilityRange.text = nil;
cell.abilityDescription.text = nil;

// Content
if (indexPath.row == 0) {
    // Passive

    // Icon
    [DDragon getChampionPassiveIcon:self.championInfo[@"passive"][@"image"][@"full"] :^(NSURL *championPassiveIconURL) {
        [cell.abilityIcon setImageWithURL:championPassiveIconURL];
    }];

    // Name
    cell.abilityNameLabel.text = self.championInfo[@"passive"][@"name"];

    // Tooltip
    cell.abilityDescription.text = self.championInfo[@"passive"][@"sanitizedDescription"];
} else {
    // Ability

    // Image
    [DDragon getChampionAbilityIcon:self.championInfo[@"spells"][indexPath.row - 1][@"image"][@"full"] :^(NSURL *championAbilityIconURL) {
        [cell.abilityIcon setImageWithURL:championAbilityIconURL];
    }];

    // Name
    cell.abilityNameLabel = self.championInfo[@"spells"][indexPath.row - 1][@"name"];

    // Cost
    cell.abilityCost.text = [NSString stringWithFormat:@"%@ %@", self.championInfo[@"spells"][indexPath.row - 1][@"costBurn"], self.championInfo[@"spells"][indexPath.row - 1][@"costType"]];

    // Range
    cell.abilityRange.text = self.championInfo[@"spells"][indexPath.row - 1][@"rangeBurn"];

    // Tooltip
    cell.abilityDescription.text = self.championInfo[@"spells"][indexPath.row - 1][@"sanitizedTooltip"];
}

return cell;
}

UITableViewCell子类

@interface ChampionDetailSpellCell : UITableViewCell

@property (strong) IBOutlet UIImageView *abilityIcon;
@property (strong) IBOutlet UILabel *abilityNameLabel;
@property (strong) IBOutlet UILabel *abilityCost;
@property (strong) IBOutlet UILabel *abilityRange;

@property (strong) IBOutlet UITextView *abilityDescription;

@end

1 个答案:

答案 0 :(得分:0)

我看错了:

//姓名

cell.abilityNameLabel = self.championInfo[@"spells"][indexPath.row - 1][@"name"];

我认为应该是:

// Name
cell.abilityNameLabel.text = self.championInfo[@"spells"][indexPath.row - 1][@"name"];