Tuesday, 20 August 2013

UICollectionview cells not disappearing

UICollectionview cells not disappearing

I have a UICollectionview with cells which look great on initial load.
However when I return to my collection view I have cells that appear
behind the ones which should be there. Odd Right?

The Code's pretty basic also, which is the weird part, the one thing I am
not doing is dequeing them. Which is likely the issue, I'm just not sure
how to fix it.
//Number of cells in collection
- (NSInteger)collectionView:(UICollectionView *)view
numberOfItemsInSection:(NSInteger)section {
return self.photoListArray.count;
}
//Number of sections
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView
*)collectionView {
return 1;
}
//layout size of given cell
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout*)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(125, 125);
}
//spacing between cells
- (UIEdgeInsets)collectionView:
(UICollectionView *)collectionView
layout:(UICollectionViewLayout*)collectionViewLayout
insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(50, 20, 50, 20);
}
//Reusable cell structure
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv
cellForItemAtIndexPath:(NSIndexPath *)indexPath {
//cell
UICollectionViewCell *cell = [cv
dequeueReusableCellWithReuseIdentifier:@"CoverImgCell"
forIndexPath:indexPath];
cell.backgroundColor = [UIColor blackColor];
Media *object = [[Media alloc] init];
object = [self.photoListArray objectAtIndex:indexPath.row];
//thumbnail
UIImageView *image = [UIImageView alloc];
image = [[UIImageView alloc] initWithImage:[UIImage
imageWithCGImage:[object.asset aspectRatioThumbnail]]];
image.layer.borderWidth = 5;
image.layer.borderColor = [UIColor whiteColor].CGColor;
//Size of Thumbnail
float newHeight = (125 / object.size.width) * object.size.height;
float newWidth = (125 / object.size.height) * object.size.width;
float newx = (125 - newWidth) / 2;
float newy = (125 - newHeight) / 2;
if (object.size.width > object.size.height) {
image.frame = CGRectMake(0, newy, 125, newHeight);
} else if (object.size.height > object.size.width) {
image.frame = CGRectMake(newx, 0, newWidth, 125);
} else {
image.frame = CGRectMake(0, 0, 125, 125);
}
[cell addSubview:image];
//Images
return cell;
}

No comments:

Post a Comment