i am creating a CollectionView app. where i am fetching data from server through JSON string. and my work flow is as follow
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".
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With