Reputation: 730
Hello I have created nib of UICollectionViewCell and set the identifier "gridcell". I am using following code but is throwing exception. Here is my code:
@implementation PhotosView
-(void)configureView:(id)object
{
event=object;
[collectionView registerClass:[PhotosCollectionViewCell class]
forCellWithReuseIdentifier:@"gridcell"];
if (photos.count<1) {
NSString* url=[NSString stringWithFormat:@"%@getImage/%d.json",kBaseURL,[event.eventId intValue]];
[self sendHttpPostJsonRequestWith:url jsonData:nil andRequestId:100];
}
}
-(void)didReceiveData:(NSData *)data error:(NSError *)error andRequestId:(int)requestId
{
if (data) {
photos=[PhotosParser parseRoot:data];
[collectionView reloadData];
}
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)aCollectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
PhotosCollectionViewCell *cell=[aCollectionView dequeueReusableCellWithReuseIdentifier:@"gridcell" forIndexPath:indexPath];
return cell;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 30;
}
@end
And the following is error:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier gridcell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
Upvotes: 0
Views: 284
Reputation: 7360
You need to register your custom cell first in viewDidLoad
Like so:
[self.yourCollectionView registerNib:[UINib nibWithNibName:@"PhotosCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"gridcell"];
Upvotes: 1