我已经在我的 View 中添加了一个 UICollectionView
。我已经实现了下面的方法。
我收到错误:
"NSInvalidArgumentException', reason: '-[NSIndexPath reuseIdentifier]: unrecognized selector sent to instance"
-(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;
}
最佳答案
- (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;
结束
关于iphone - ios添加UICollectionView reuseIdentifier报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15153063/