lundi 29 décembre 2014

UICollectionView didSelectItemAtIndexPath, how to pass random images from cellForItemAtIndexPath?


Vote count:

0




I'm using Parse database to show an array of images in my UICollectionView with a random index, but I need to show them in an alert when the user selects the item, so how can I retrieve the images properly in didSelectItemAtIndexPath ?! Thanks!!



- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
//static
NSString *identifier = @"cell";


AppDelegate *appDelegate= (AppDelegate *)[[UIApplication sharedApplication]delegate];




UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];


int imgRandom = arc4random() % appDelegate.immaginihome.count;

NSDictionary* dictionary = appDelegate.immaginihome[imgRandom];


_eventImage = dictionary[@"ImmaginiHome"];


if(_eventImage != NULL)
{



[_eventImage getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {


_image = [UIImage imageWithData:data];




UIImageView *recipeImageView = [[UIImageView alloc]init];
recipeImageView.image = _image;

recipeImageView.frame=cell.bounds;


recipeImageView.layer.shadowColor = [[UIColor blackColor] CGColor];
recipeImageView.layer.shadowOpacity = 0.5;
recipeImageView.layer.shadowOffset = CGSizeMake(2,3);
recipeImageView.clipsToBounds = NO;
recipeImageView.layer.drawsAsynchronously=YES;


recipeImageView.layer.borderWidth = 2.0;
recipeImageView.layer.borderColor = [UIColor whiteColor].CGColor;


[cell addSubview:recipeImageView];


}];


} // else if (_eventImage==NULL){}



return cell;}


asked 44 secs ago







UICollectionView didSelectItemAtIndexPath, how to pass random images from cellForItemAtIndexPath?

Aucun commentaire:

Enregistrer un commentaire