I am sending the data to collection view but I am getting the error [__NSCFConstantString objectAtIndex:]: unrecognized selector sent to instance.
Please help me. Thank you.
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
// NSURL *imageURL = [NSURL URLWithString:str1];
// NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
// UIImage *image = [UIImage imageWithData:imageData];
// thumbnailImgView.image = image;
static NSString *identifier = @"Cell";
CustomCell *cell = (CustomCell *)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UIImageView *recipeImageView = (UIImageView *)[cell viewWithTag:100];
recipeImageView.image = [UIImage imageNamed:[recipeImages[indexPath.section] objectAtIndex:indexPath.row]];
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img.png"]];
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"One-Album.png"]];
return cell;
}
This line seems to be wrong [recipeImages[indexPath.section] objectAtIndex:indexPath.row]
If recipeImages
is a type of NSArray
or NSMutableArray
, you should use [recipeImages objectAtIndex:indexPath.row]
.
Example:
if([recipeImages count] > indexPath.row)
{
recipeImageView.image = [UIImage imageNamed:[recipeImages objectAtIndex:indexPath.row]];
}
else
{
NSLog(@"Unable to get the image name");
}