开发者社区> 问答> 正文

ios添加UICollectionView报错

我添加了UICollectionViewview中。然后报错了。

错误:
`
"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;
}

展开
收起
爵霸 2016-03-24 11:27:17 2356 0
1 条回答
写回答
取消 提交回答
  • 你如果是代码创建的话 要注册cell kcellID是你的identifier
    [collectionView registerClass:[Cell class] forCellWithReuseIdentifier:kCellID];

    如果是storyboard创建的话

    storyboard中选中cell view cell中有个identifier改成你的identifier

    2019-07-17 19:12:26
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

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