Im having a problem with my UICollectionView
. Initially it displays fine, showing a grid of cells, each cell with a single UIImageView
. These
That Happen because you add every time a UIImageView
to your cell for fix this problem you have to Make a custom cell and then use it like take:
Custom.h
#import <UIKit/UIKit.h>
@interface CustomCell : UICollectionViewCell
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
Custom.m
#import "CustomCell.h"
@implementation CustomCell
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
Your Controller
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CustomCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"CustomCell" forIndexPath:indexPath];
NSString * buttonPath=[[NSBundle mainBundle] pathForResource:@"button" ofType:@"png" inDirectory:[[buttons objectAtIndex:indexPath.row] objectForKey:@"name"]];
UIImage * button=[UIImage imageWithContentsOfFile:buttonPath];
[cell.imageView setImage:button];
return cell;
}
You have also to set 'CustomCell' like Identifier to the Cell in IB