滚动经过第一行时 UICollectionView 崩溃

UICollectionView crashes when scrolling past first row

我有一个对象数组,用于填充自定义 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,保留策略是否设置为强(或复制,这可能更合适)?