我有一个对象数组,用于填充自定义UICollectionViewCell的标签文本。当我启动应用程序时,单元格显示正常,但是当我滚动到第一行单元格时,应用程序崩溃。我启用了僵尸,崩溃前调试的最后一行是:
*** -[CFString retain]: message sent to deallocated instance 0x174233be0
这是返回每个单元格的代码:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"BadgeCell";
BadgeCell *cell = (BadgeCell *)[badgeCollectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
Badge *cellData = dataArray[indexPath.row];
[cell.titleLabel setText:cellData.badgeName];
return cell;
}
编辑:BadgeCell中的代码:
@synthesize titleLabel;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"BadgeCell" owner:self options:nil];
if ([arrayOfViews count] < 1)
{
return nil;
}
if (![[arrayOfViews objectAtIndex:0] isKindOfClass:[UICollectionViewCell class]])
{
return nil;
}
self = [arrayOfViews objectAtIndex:0];
}
return self;
}
最佳答案
我怀疑您的模型没有正确保留此属性(NSString *)badgeName,保留策略是否设置为“强”(或“复制”,可能更合适)?