滚动到第一行时,UICollectionView崩溃

时间:2015-03-14 21:42:34

标签: ios objective-c uicollectionview uicollectionviewcell

我有一个对象数组,我正在填充自定义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;
}

0 个答案:

没有答案