简体   繁体   中英

UICollectionView and UICollectionViewCell IndexPath error

I am new to UICollectionView s, and I keep running into a specific error when I try to add UICollectionViewCell s programmatically.

In my app, I have one UIViewController that holds a UIView . Within this UIView , there are a few objects on the top half, and the bottom half holds a UIScrollView . This UIScrollView holds a UICollectionView .

I am attempting to add custom UICollectionViewCell s to the UICollectionView programmatically, and I keep getting this error:

[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'

I've tried almost every solution from somewhat similar threads, but nothing has worked.

Here's the code that I believe is producing the problem:

- (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;
}

I can post any more information that is requested!

Read the error message; you're missing a method, because you've named your method incorrectly.

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

That means your collectionView:cellForItemAtIndexPath: method is missing. And if you look at the definition of your method, you'll see you actually called it myCollectionView:cellForItemAtIndexPath: .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM