Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue in unrecognized selector sent to instance

i am creating a CollectionView app. where i am fetching data from server through JSON string. and my work flow is as follow

  1. Created Collection View Cell as ProjectVCollectionViewCell.h, .m, .xib.

    Code for .h is -

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

Code for .m is default and synthesized the above 2 variables. and .xib has Collection View Cell with Image View and Label (Linked the above class with collection view cell and linked the identifier name as "projectCell".

  1. Code for its ViewController, contains collectionView, is as follow

Code inside for ViewController.m is

- (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 Above Code cell.projectlabel is giving me issue

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

cell value is fine, i traced that with NSLog and code hint is also taking projectLabel after ".". But i am not able to set the label field value by this. So please help me out.

like image 380
VarunJi Avatar asked Nov 03 '22 05:11

VarunJi


1 Answers

In the case create custom ProjectCollectionViewCell with ProjectCollectionViewCell.xib, you must registerNib in viewDidLoad:

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

You should change to use StoryBoard for save time with CollectionView. Don't need to register anything, just select customCell, drag and drop everything you want into CollectionView cell and drag IBOutlet: https://github.com/lequysang/testCollectionViewScroll

like image 70
LE SANG Avatar answered Jan 04 '23 15:01

LE SANG