How to load UIImage to UICollectionView from an array of UIImage
So after saving UIImage to a NSMutableArray from ImagePickerController I
want to load the images to UICollectionView, however the cells are not
displaying anything even though the array isn't nil.
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[_imgs addObject:image];
[picker dismissModalViewControllerAnimated:YES];
[self.collectionView reloadData];
NSLog(@"%d", [_imgs count]);
//[self viewDidLoad];
}
- (UICollectionViewCell *)collectionView:(UICollectionView
*)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
Icon *icon = [collectionView
dequeueReusableCellWithReuseIdentifier:@"ICON" forIndexPath:indexPath];
UIImageView *recipeImageView = (UIImageView *)[icon viewWithTag:100];
recipeImageView.image = [UIImage imageNamed:[self.imgs
objectAtIndex:indexPath.row]];
icon.image = (UIImage*)[self.imgs objectAtIndex:indexPath.row];
[icon.deleteButton addTarget:self action:@selector(delete:)
forControlEvents:UIControlEventTouchUpInside];
#pragma mark - delete for button
return icon;
}
@implementation Icon
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
UIView *insetView = [[UIView alloc]
initWithFrame:CGRectInset(self.bounds, 300, 400)];
self.image = [[UIImage alloc]init];
UIImageView *img =[[UIImageView alloc]initWithImage:self.image];
[self.contentView addSubview:insetView];
[insetView addSubview:img];
self.layer.shouldRasterize = YES;
I created a class called ICON class to wrap the cells.
No comments:
Post a Comment