-
-
Save yuguo/f0cd3f56050c30fc4a40 to your computer and use it in GitHub Desktop.
prepareForSegue:sender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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