ios - UICollectionView 和 UICollectionViewCell IndexPath 错误

标签 ios objective-c xcode uicollectionview

我是 UICollectionView 的新手,当我尝试以编程方式添加 UICollectionViewCell 时,我一直遇到特定错误。

在我的应用程序中,我有一个包含 UIViewUIViewController。在这个 UIView 中,上半部分有几个对象,下半部分包含一个 UIScrollView。此 UIScrollView 包含一个 UICollectionView

我试图以编程方式将自定义 UICollectionViewCell 添加到 UICollectionView,但我不断收到此错误:

[myViewController collectionView:cellForItemAtIndexPath:]: unrecognized selector sent to instance 0x1e01f5e0
2013-04-23 16:19:02.726 myAppName[28121:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[myViewController collectionView:cellForItemAtIndexPath:]: unrecognized selector sent to instance 0x1e01f5e0'

我已经尝试了几乎所有类似线程的解决方案,但没有任何效果。

这是我认为产生问题的代码:

- (UICollectionViewCell *)myCollectionView:(UICollectionView *)myCollectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
  NSMutableArray *data = [self.dataArray objectAtIndex:indexPath.section];
  NSString *cellData = [data objectAtIndex:indexPath.row];
  static NSString *cellIdentifier = @"cvCell";
  UICollectionViewCell *cell = [myCollectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
  UILabel *myCellTextLabel = (UILabel *)[cell viewWithTag:100];
  [myCellTextLabel setText:cellData];

  return cell;
}

我可以发布所要求的任何更多信息!

最佳答案

阅读错误信息;你错过了一个方法,因为你错误地命名了你的方法。

[myViewController collectionView:cellForItemAtIndexPath:]: unrecognized selector sent to instance 0x1e01f5e0

这意味着您的 collectionView:cellForItemAtIndexPath: 方法丢失了。如果您查看方法的定义,您会发现实际上将其命名为 myCollectionView:cellForItemAtIndexPath:

关于ios - UICollectionView 和 UICollectionViewCell IndexPath 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16180965/

相关文章:

ios - webdriveragentrunner iphoneos12.2-arm64.xctestrun 不存在

iphone - 如何解析 iPhone SDK 中的 JSON 对象?

ios - 将 Redis 库编译到 iOS 项目 ("_OBJC_CLASS_$_ObjCHiredis"时出错,引用自 :)

windows - 跨多个操作系统平台的代码签名证书 - 与 Adob​​e Air 软件包相关

iphone - textFieldDidBeginEditing 和 textFieldShouldBeginEditing 之间的确切区别是什么

ios - 处理触摸而不消耗它

ios - Objective C 中的 RSA 实现

ios - 在 IOS 中从 UIImage 获取坐标和框架

iphone - UIImageView 不遵循 origin.x 位置

javascript - JQuery keyup() keydown() 和 keypress() 不适用于 iPad 和蓝牙键盘