【发布时间】:2015-10-29 10:44:34
【问题描述】:
所以我有一个带有 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
【问题讨论】:
-
僵尸对象的配置文件并告诉我们结果。
标签: ios objective-c uitableview