首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ios添加UICollectionView reuseIdentifier错误

ios添加UICollectionView reuseIdentifier错误
EN

Stack Overflow用户
提问于 2013-03-01 07:58:52
回答 2查看 2.2K关注 0票数 0

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

我得到错误:

"NSInvalidArgumentException',原因:'-NSIndexPath reuseIdentifier:未识别的选择器发送到实例‘“

代码语言:javascript
复制
-(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;
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-03-01 08:02:12

代码语言:javascript
复制
- (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;添加到末尾。

票数 2
EN

Stack Overflow用户

发布于 2014-04-04 03:02:27

细胞需要注册到CollectionView之前,

代码语言:javascript
复制
   [self.dateCollectionView registerClass:[DateCell Class] forCellWithReuseIdentifier:identifier];

见标识符

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15153063

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档