If the cell selection triggers the segue instantly, you can make use of the indexPathForSelectedItems
method of UICollectionView
to get the indexPath
that you need to get your NSManagedObject
.
Try this:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"newsDetail"]) {
NewsDetailViewController *vc =[segue destinationViewController];
// In the following line, replace self.collectionView with your UICollectionView
NSIndexPath *indexPath = [[self.collectionView indexPathsForSelectedItems] objectAtIndex:0];
NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSURL *photoURL = [NSURL URLWithString:(NSString *)[object valueForKey:@"imageUrl"]];
NSData *photoData = [NSData dataWithContentsOfURL:photoURL];
UIImage *img = [[UIImage alloc] initWithData:photoData];
vc.newsDetailImageView = [[UIImageView alloc] initWithImage:img];
vc.newsDetailText = howeverYouGetYourObjectSummary;
}
}