我是 UICollectionView
的新手,当我尝试以编程方式添加 UICollectionViewCell
时,我一直遇到特定错误。
在我的应用程序中,我有一个包含 UIView
的 UIViewController
。在这个 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 instance0x1e01f5e0
这意味着您的 collectionView:cellForItemAtIndexPath:
方法丢失了。如果您查看方法的定义,您会发现实际上将其命名为 myCollectionView:cellForItemAtIndexPath:
。
关于ios - UICollectionView 和 UICollectionViewCell IndexPath 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16180965/