Skip to content

Instantly share code, notes, and snippets.

@yuguo
Created Dec 16, 2012
Embed
What would you like to do?
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