0

我已经在我的视图中添加了一个UICollectionView。我已经实现了下面的方法。

我得到错误:

“NSInvalidArgumentException”,原因:'-[NSIndexPath reuseIdentifier]:无法识别的选择器发送到实例”

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 1;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"CellID";
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

    UIImageView *imageView = (UIImageView *)[cell viewWithTag:10];
    imageView.image = [UIImage imageNamed:@"V.jpg"];
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
4

2 回答 2

2
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"CellID";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

UIImageView *imageView = (UIImageView *)[cell viewWithTag:10];
imageView.image = [UIImage imageNamed:@"V.jpg"];

    return cell; // here is ur mistake
}

添加return cell;到结尾。

于 2013-03-01T08:02:12.797 回答
1

单元格需要注册到 CollectionView 之前,

   [self.dateCollectionView registerClass:[DateCell Class] forCellWithReuseIdentifier:identifier];

看标识符

于 2014-04-04T03:02:27.797 回答