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 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图