开发者社区> 问答> 正文

ios添加UICollectionView报错 ?报错

我添加了UICollectionView到view中。然后报错了。

错误:

"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;
}

展开
收起
爱吃鱼的程序员 2020-06-23 01:30:32 443 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    你如果是代码创建的话要注册cellkcellID是你的identifier
    [collectionViewregisterClass:[Cellclass]forCellWithReuseIdentifier:kCellID];

    如果是storyboard创建的话

    在storyboard中选中cell把viewcell中有个identifier改成你的identifier
    你试试看

    2020-06-23 01:30:49
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
手淘iOS性能优化探索 立即下载
From Java/Android to Swift iOS 立即下载
深入剖析iOS性能优化 立即下载