UICollectionView不显示细胞(UICollectionView don't s

2019-10-29 12:11发布

UIViewController包含UICollectionView 。 也有UICollectionViewCell它有自己的类和厦门国际银行(CurrentCell.h,CurrentCell.m,CurrentCell.xib)。

在我UIViewController.h

@property (strong, nonatomic) IBOutlet UICollectionView *collection;

在我UIViewController.m

@synthesize collection;

viewDidLoad中

[self.collection registerClass:[CurrentCell class] forCellWithReuseIdentifier:@"cellCurRecipe"];

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setItemSize:CGSizeMake(120, 90)];
[flowLayout setSectionInset:UIEdgeInsetsMake(5, 10, 5, 10)];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
[self.collection setCollectionViewLayout:flowLayout];

cellForItemAtIndexPath:

static NSString *CellIdentifier = @"cellCurRecipe";    
CurrentCell *cell = (CurrentCell *)[self.collection dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];   
Recipes *recipe = [currRecipesArray objectAtIndex:indexPath.item];  
[cell.image setImage: recipe.image]; 
return cell;

但是:如果我直观地挖掘到小区didSelectItemAtIndexPath方法调用。

EDITED

现在一切正常!

我忘了初始化的细胞中CurrentCell.m:

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"CurrentCell" 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;
}

Answer 1:

注册笔尖,而不是类。 您应该只需要注册一个类,如果电池在代码完全由。 如果使用的是厦门国际银行,然后注册的是(与registerNib:forCellWithReuseIdentifier :)。 如果您的电池在故事板,然后不登记任何东西。



文章来源: UICollectionView don't show the cell