iphone - ios添加UICollectionView reuseIdentifier报错

标签 iphone ios objective-c cocoa-touch

我已经在我的 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/

相关文章:

iphone - 如何从底部uitableview返回主viewcontroller

ios - 通过点击 UITextField 判断是否有打开键盘的条件

iphone - 为什么约束不适用于 UIView 但适用于 UILabel?

ios - 我可以在要提交给应用商店的应用程序中使用SpringBoardServices吗?

ios - 录制带有附加效果的音频

iphone - 如何停止在iPhone中执行线程

iphone - 用于 ios 开发的 Windows 上的 Xcode

ios - 使用 Swift 将信息从 ViewController 传递到 ViewController

objective-c - 将 SBJson framwork + ShareKit/ShareKit 添加到同一个 XCode 项目

objective-c - 在滑动之前允许延迟