Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to send image from Collection View Controller to Detail View Controller
    primarykey
    data
    text
    <p>What I have is an array of file names. Here is the code that i have used to fill Collection View Cells.</p> <pre><code> -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ReuseID" forIndexPath:indexPath]; NSString *dataPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/DrawnImage"]; NSArray *contentOfDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:dataPath error:NULL]; NSString *fileName = [contentOfDirectory objectAtIndex:indexPath.item]; NSString *path = [dataPath stringByAppendingPathComponent:fileName]; UIImage *image = [UIImage imageWithContentsOfFile:path]; UIImageView *cellImageView = cell.collectionImageView; cellImageView.image = image; return cell; </code></pre> <p>}</p> <p>The images are being correctly displayed in the cells. What i want to do it, when i click on a cell, The picture in that cell must be displayed in full screen in a detail view controller.</p> <p>I have tried this.</p> <pre><code> - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"showDetail"]) { NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] objectAtIndex:0]; NSString *dataPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/DrawnImage"]; NSArray *contentOfDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:dataPath error:NULL]; NSString *fileName = [contentOfDirectory objectAtIndex:selectedIndexPath.item]; NSString *pathToImage = [dataPath stringByAppendingPathComponent:fileName]; UIImage *image = [[UIImage alloc] initWithContentsOfFile:pathToImage]; UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:image]; DetailViewController *dvc = [segue destinationViewController]; dvc.finalImage = sender; NSLog(@"%@", backgroundImageView); } </code></pre> <p>}</p> <p>finalImage is an UIImageView in Detail View Controller. I get a run time error when i click one of the cells. What am I doing wrong ?</p> <p><strong>EDIT</strong></p> <p>This is the code that I have right now.</p> <p>CollectionViewController.h</p> <pre><code>@property (nonatomic, retain) UIImage *sendImage; </code></pre> <p>CollectionViewController.m</p> <pre><code>- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"showDetail"]) { NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] objectAtIndex:0]; NSString *dataPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/DrawnImage"]; NSArray *contentOfDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:dataPath error:NULL]; NSString *fileName = [contentOfDirectory objectAtIndex:selectedIndexPath.item]; NSString *pathToImage = [dataPath stringByAppendingPathComponent:fileName]; UIImage *image = [[UIImage alloc] initWithContentsOfFile:pathToImage]; DetailViewController *dvc = [segue destinationViewController]; dvc.passedInImage = image; image = dvc.passedInImage; } } </code></pre> <p>DetailViewController.h</p> <pre><code>@property (weak, nonatomic) IBOutlet UIImageView *finalImage; @property UIImage *passedInImage; </code></pre> <p>DetailViewController.m</p> <pre><code>-(void)viewDidAppear:(BOOL)animated { self.finalImage.image = passedInImage; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload