guodegangGDG 2013-04-17 02:02 采纳率: 0%
浏览 1299

collectionView出现的错误

在将UITable转换为collectionView时出了问题。

实现代码如下,但是在这里报错: collectionView dequeueReusableCellWithIdentifier

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
//  Return the number of rows in the section (the amount of items in our array)
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return [pictureListData count];
}
//  Create / reuse a table cell and configure it for display
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
                  cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";
    UICollectionViewController *cell = [collectionView dequeueReusableCellWithIdentifier:CellIdentifier];
    // Get the core data object we need to use to populate this table cell
    Pictures *currentCell = [pictureListData objectAtIndex:indexPath.row];
  • 写回答

1条回答 默认 最新

  • ChatGPTᴼᴾᴱᴺᴬᴵ 2022-12-21 14:12
    关注

    ChatGPT尝试为您解答,仅供参考
    在调用dequeueReusableCellWithIdentifier:方法时,您应该传递一个字符串作为参数,该字符串是创建单元格时使用的标识符。您应该使用与您在故事板中设置的相同的标识符。


    例如,如果您在故事板中使用的标识符是“MyCell”,则应使用以下代码调用此方法:

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithIdentifier:@"MyCell"];
    

    注意,在使用自定义的单元格类时,您还应该使用相同的标识符将单元格类与故事板中的单元格连接起来。例如:

    MyCustomCell *cell = [collectionView dequeueReusableCellWithIdentifier:@"MyCell" forIndexPath:indexPath];
    

    如果您在调用此方法时遇到错误,请检查您是否正确使用了标识符。

    评论

报告相同问题?

悬赏问题

  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条