2013-04-23 67 views
0

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

在我的应用程序中,我有一个UIViewController持有UIView。在这个UIView的上半部分有一些物体,下半部分有UIScrollView。这UIScrollView持有UICollectionView

我试图定制UICollectionViewCell s添加到了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; 
} 

我可以张贴任何被请求的详细信息!

+0

UICollectionView继承自UIScrollView,因此您可能不需要将它放在另一个滚动视图中。 – Caleb 2013-04-24 00:30:59

回答

2

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

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

这意味着您的collectionView:cellForItemAtIndexPath:方法丢失。如果你看看你的方法的定义,你会看到你实际上称它为myCollectionView:cellForItemAtIndexPath:

+0

这个固定我的问题!我正在使用我的collectionView的实际名称,而不是方法中的“collectionView”。这现在非常有意义。我看到了我的菜鸟错误。 – tagabek 2013-04-24 00:07:41

相关问题