Note that there are some explanatory texts on larger screens.

plurals
  1. POsegueing from collection view to detail view problems
    primarykey
    data
    text
    <p>I'm slowly going out of my mind trying to replicate an iPhone photo gallery with a collection view segueing to a detail view and I want the detail view to have paging just like the photo gallery does. The code I have so far seems to load but then has an error. I have exemption breakpoints on and the breakpoint 1.1 crash point is the line self.imageView.image = img;. This doesn't say anything about the error on the log other than (lldb).</p> <p>I was wondering if I can borrow someones genius to point out where I have gone wrong and perhaps correct it? I would also like to take a title for each image across to the detail view but didn't know how/where to add this in. </p> <p>The code I have is:</p> <pre><code>#import "MarbleCollectionViewController.h" #import "DetailViewController.h" @interface MarbleCollectionViewController () { NSArray *marbleImages; } @end @implementation MarbleCollectionViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; marbleImages = [NSArray arrayWithObjects:@"arabescato.jpg", @"bianco-carrara.jpg", @"botticino-classico2.jpg", @"Calacatta_Oro.jpg", @"crema-marfil-3.jpg", @"crema-valencia.jpg", @"emperador-dark.jpg", @"jura-beige.jpg", @"nero-marquina.jpg", @"perlato-olympo.jpg", @"rojo-alicante_marbleGRP1.jpg", nil]; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return marbleImages.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ static NSString *identifier = @"Cell"; UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; UIImageView *marbleImageView = (UIImageView *)[cell viewWithTag:100]; marbleImageView.image = [UIImage imageNamed:[marbleImages objectAtIndex:indexPath.row]]; return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { [self performSegueWithIdentifier:@"detailView" sender:collectionView]; } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"detailView"]) { DetailViewController *destViewController = segue.destinationViewController; NSIndexPath *indexPath = [[self.collectionView indexPathsForSelectedItems] objectAtIndex:0]; destViewController.img = [marbleImages objectAtIndex:indexPath.row]; [self.collectionView deselectItemAtIndexPath:indexPath animated:NO]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end </code></pre> <p>and the detail view is:</p> <pre><code>#import "DetailViewController.h" @interface DetailViewController () @end @implementation DetailViewController @synthesize imageView, img; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; self.imageView.image = img; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end </code></pre> <p>A massive thank you for any help you can offer is in order and I really really do appreciate it.</p>
    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