- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
//NSString *sectionName= [[sections objectAtIndex:indexPath.row] objectAtIndex:0];
[self performSegueWithIdentifier:@"gotoDetail" sender:self];
}
上面代码执行后会触发下面的事件。
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
//pass the section id and section name to detail page.
if([segue.identifier isEqualToString:@"gotoDetail"])
{
DetailViewController *detailView=[segue destinationViewController];
NSIndexPath *selectedIndexPath=[[self.collectionView indexPathsForSelectedItems] lastObject];
NSInteger row=selectedIndexPath.row;
NSArray *item= [sections objectAtIndex:row];
NSString *key=item[0];
NSString *sectionName=[dic objectForKey:key];
// Section *selectedSection=[[Section alloc] ];
Section *s=[[Section alloc] initWithIdAndName:key sectionName:sectionName];
detailView.section=s;
}
}