Skip to content

Instantly share code, notes, and snippets.

@yuguo
Created December 16, 2012 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuguo/f0cd3f56050c30fc4a40 to your computer and use it in GitHub Desktop.
Save yuguo/f0cd3f56050c30fc4a40 to your computer and use it in GitHub Desktop.
prepareForSegue:sender
// the user tapped a collection item, load and set the image on the detail view controller
//
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"])
{
NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] objectAtIndex:0];
// load the image, to prevent it from being cached we use 'initWithContentsOfFile'
NSString *imageNameToLoad = [NSString stringWithFormat:@"%d_full", selectedIndexPath.row];
NSString *pathToImage = [[NSBundle mainBundle] pathForResource:imageNameToLoad ofType:@"JPG"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:pathToImage];
DetailViewController *detailViewController = [segue destinationViewController];
detailViewController.image = image;
}
}
// Do some customisation of our new view when a table item has been selected
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Make sure we're referring to the correct segue
if ([[segue identifier] isEqualToString:@"ShowSpeaker"]) {
// Get reference to the destination view controller
DDSpeakerViewController *vc = [segue destinationViewController];
// get the selected index
NSInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];
// grab the speaker dictionary
NSDictionary *speaker = [self.speakers objectAtIndex:selectedIndex];
// Pass the name to our view controller
vc.name = [speaker objectForKey:@"name"];
// Pass the description to our view controller
vc.description = [speaker objectForKey:@"description"];
// Pass the imagePath to our view controller
vc.imagePath = [speaker objectForKey:@"image"];
// Pass the organizagtion to our view controller
vc.organization = [speaker objectForKey:@"organization"];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment