コレクションビューに異なるサイズのセルを作成したい。collectionViewLayout sizeForItemAtIndexPathで、CGSizeオブジェクトを使用して配列を作成しました。NSArray(NSMutableArrayと同じ)に格納されているオブジェクトを取得したい場合、次のセマンティックの問題が発生します。
Returning 'id' from a function with incompatible result type 'CGSize' (aka 'struct CGSize')
配列内のCGSizeオブジェクトにアクセスするにはどうすればよいですか?
編集:配列に格納されている値はNSSize型のものであることがわかりました。
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
UIImage *image;
int row = [indexPath row];
NSArray *mElements = [NSArray arrayWithObjects:[NSValue valueWithCGSize:CGSizeMake(306.0, 270.0)],
[NSValue valueWithCGSize:CGSizeMake(100.0, 150.0)],
[NSValue valueWithCGSize:CGSizeMake(200.0, 150.0)],
[NSValue valueWithCGSize:CGSizeMake(200.0, 150.0)],
[NSValue valueWithCGSize:CGSizeMake(100.0, 150.0)],
nil];
return [mElements objectAtIndex:row]; // Semantic issue
}
私が理解していないのは、別の部分では同じアプローチが機能するということです...
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CollectionViewCell *myCell = (CollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:Cellid forIndexPath:indexPath];
int row = [indexPath row];
myCell.cellImageView.image = [self.searches objectAtIndex:row]; // Here it works...
return myCell;
}
CGSizeオブジェクトを含む配列ではなく、UIImagesを含む配列で機能するのはなぜですか?
乾杯-ジェリック