我想在collectionview中創建不同大小的單元格。在collectionViewLayout sizeForItemAtIndexPath我創建了一個數組與CGSize對象。當我想要檢索存儲在NSArray中(與NSMutableArray的相同)的對象,我得到以下語義問題:使用gcsize對象訪問數組
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;
}
爲什麼它與UIImages而不是與CGSize對象的數組,數組的工作?
歡呼聲 - jerik
嘗試你的代碼,拋出一個SIGABRT。我想用'NSLog(@「size:%@」,[[magazinElements objectAtIndex:row] CGSizeValue]);'得到這個問題信息:'Format指定類型'id',但參數的類型爲' CGSize'(又名'struct CGSize')' – jerik
@jerik不是我的錯。那麼你做了一些不一致的事情。此代碼是正確的。 – 2013-01-31 22:46:16
我只是做了上面的代碼... – jerik