I use the tapGesture method to pouch the image from UICollectionView to detailViewController viewController.h as follows:
#import <Parse/Parse.h>
@interface CardsViewController : UIViewController <UICollectionViewDelegateFlowLayout> {
NSMutableArray *allImages;
NSArray *cardFileArray;
}
@property (weak, nonatomic) IBOutlet UICollectionView *imageCollection
and viewController.m as the follow
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return [cardFileArray count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"MyCell";
Cards *cell = (Cards *)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
PFObject *imageObject = [cardFileArray objectAtIndex:indexPath.row];
PFFile *imageFile = [imageObject objectForKey:KEY_IMAGE4];
cell.spinController.hidden = NO;
[cell.spinController startAnimating];
[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
cell.imageView.image = [UIImage imageWithData:data];
[cell.spinController stopAnimating];
cell.spinController.hidden = YES;
}
}];
return cell;
}
- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture{
CGPoint touchPoint = [gesture locationInView:imageCollection];
NSUInteger touchPage = floorf(touchPoint.x / imageCollection.frame.size.width);
NSIndexPath *indexPath = [imageCollection indexPathForItemAtPoint:touchPoint];
if (indexPath == nil) {
touchPage = touchPage % ([allImages count]);
}
//Push the image to another view
detailViewController*ptvc = [self.storyboard instantiateViewControllerWithIdentifier:@"imageDetail"];
[self.navigationController pushViewController:ptvc animated:YES];
ptvc.imageString = [cardFileArray objectAtIndex:touchedPage];
}
the detailViewController.h as follow
@property (strong, nonatomic) IBOutlet UIImageView *Preview;
@property (strong, nonatomic) UIImage *imagePreview;
so for the DetailViewController i put in viewDidload this line
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//self.imageView.image = [UIImage imageNamed:self.imageViewDetail];
self.Preview.image = self.imagePreview;
}
but the app make crash and mark the line on the viewDidload ; so any advice i need to puch the image on uicollectionView to detailView