Error in unrecognized selector sent to instance

I am creating a CollectionView application. where I get data from the server through a JSON string. and my workflow is as follows

  • The View Cell collection has been created as ProjectVCollectionViewCell.h, .m, .xib.

    The code for .h is -

@interface ProjectCollectionViewCell: UICollectionViewCell
    @property (weak, non-nuclear) IBOutlet UIImageView * projectImage,
    @property (weak, non-nuclear) IBOutlet UILabel * projectLabel;
    @end

The code for .m is by default and synthesized the above 2 variables. and .xib has a View Cell collection with an image and label (linked the above class to the collection view cell and linked the identifier name as "projectCell".

  • The code for the ViewController containing the collectionView is as follows

Code inside for ViewController.m

- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section{
    return [projectList count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
    ProjectCollectionViewCell *cell = (ProjectCollectionViewCell *)[cv dequeueReusableCellWithReuseIdentifier:@"projectCell" forIndexPath:indexPath];    

    cell.projectLabel.text = @"";//Here i am getting issue
    //cell.projectLabel.text = [[NSString alloc] initWithString:[[projectList objectAtIndex:indexPath.row] objectForKey:@"albumName"]];        
    return cell;
}

in the "Above code" box. I need a problem.

[UICollectionViewCell projectLabel]: unrecognized selector sent to instance 0x75f0fb0
2013-02-07 20:08:17.723 Sample[3189:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UICollectionViewCell projectLabel]: unrecognized selector sent to instance 0x75f0fb0'
*** First throw call stack:

The cell value is beautiful, I made sure that projectLabel after "." Is also taken with NSLog and code hint. But I can not set the value of the label field with this. So please help me.

+5
source share
1 answer

If you create a custom ProjectCollectionViewCell with ProjectCollectionViewCell.xib, you must register the Nib in viewDidLoad:

[self.projectListView registerNib:[UINib nibWithNibName:@"ProjectCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"projectCell"];

StoryBoard CollectionView. , customCell, , , CollectionView IBOutlet: https://github.com/lequysang/testCollectionViewScroll

+2

All Articles