I have a collection view of 10 images, and each when pressed is supposed to go to a detail view that displays that image, however I need help pushing the image from the collection view to the detail view. The code I have that grabs all the images is this:
-(MyCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CELL" forIndexPath:indexPath];
PFObject *imageObject = [imageFilesArray objectAtIndex:indexPath.row];
__block UIImage *MyPicture = [[UIImage alloc]init];
PFFile *imageFile = [imageObject objectForKey:@"test"];
[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
MyPicture = [UIImage imageWithData:data];
cell.CollectionImg.image = [UIImage imageWithData:data];
}
}];
return cell;
}
And here is the code for the selection of the image:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
TableDetailViewController *objDetail = [[TableDetailViewController alloc] initWithNibName:@"TableDetailViewController" bundle:nil];
[self addChildViewController:objDetail];
objDetail.view.frame = CGRectMake(0.0f, 0.0f, 320.0f, 568.0f);
[self.view addSubview:objDetail.view];
}
And I am not even sure what to write in the view did load on the TableDetailViewController. If someone can help me out I would greatly appreciate it.
It's unlikely you want to addChildViewController: and addSubview:. More common patterns for this are to use presentViewController: if you want a modal detail view, or have a navigationController and use [[self navigationController] pushViewController:...] if you want a back button and all that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.