If using storyboard, just add new ViewController to the scene and Ctrl-drag from the CollectionView cell to the ViewController to create segue. Choose modal if you want full screen.
In your CollectionViewController class, you need to pass the image reference to a property of the Detail ViewController. You need to use a public property, as the Outlet for the image is not set yet when the detailVC loads. After its instantiated, you just set the image to the Outlet to display it.
MyCVC.m (subclass of UICollectionViewController)
#import "MyCVC.h"
#import "DetailVC.h"
@interface MyCVC ()
@end
@implementation MyCVC
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"detailSegue"] && [segue.destinationViewController isKindOfClass:[DetailVC class]]) {
DetailVC *detailVC = segue.destinationViewController;
detailVC.image = sender.image; // or any other reference to the actual image to display
}
}
@end
DetailVC.h
#import <UIKit/UIKit.h>
@interface DetailVC : UIViewController
@property (strong, nonatomic) UIImage *image;
@end
DetailVC.m
#import "DetailVC.h"
@interface DetailVC ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
@implementation DetailVC
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.imageView.image = self.image;
}
@end
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…