I have check a lot of links regarding this but i could not come to a conclusion. What i want to do is have dynamic size for cells of a UICollectionView. I have an array of images with different sizes and i want to display them. I can't figure out why other answers on SO are so complicated for this problem, what i understand is, i just need to calculate the size of image in the sizeForItemAtIndexPath method as mentioned here but i am getting an error, *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString size]: unrecognized selector sent to instance 0x10fc860a0
My implementation for sizeForItemAtIndexPath is as,
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
UIImage *image = [arrRecipeImages objectAtIndex:indexPath.row];
CGSize size = CGSizeMake(image.size.width, image.size.height);
return size;
}
Everything looks fine to me, can someone point out where i am going wrong, thanks in advance.