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];
    

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

    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题