0
我得到了一個名爲SecondViewController的UIViewController,它使用UIImagePickerController加載照片庫。當我選擇一張照片時,它應該顯示另一個名爲PhotoViewController的視圖控制器。爲了將圖像從SecondViewController傳遞到PhotoViewController,我使用了一個單例。下面是代碼:presentViewController之後的黑屏
SecondViewController:
@property (strong,nonatomic) UIImagePickerController *libraryPicker;
@property (strong,nonatomic) UIImage *chosenImage;
@property (strong,nonatomic) PhotoViewController *controller;
- (void)viewDidLoad
{
controller = [PhotoViewController sharedInstance];
libraryPicker = [[UIImagePickerController alloc] init];
libraryPicker.delegate = self;
libraryPicker.allowsEditing = NO;
libraryPicker.navigationBarHidden = NO;
libraryPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentViewController:libraryPicker animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
chosenImage = [info objectForKey:UIImagePickerControllerOriginalImage];
controller.photo = chosenImage;
[libraryPicker dismissViewControllerAnimated:NO completion:nil];
[self presentViewController:controller animated:YES completion:nil];
}
PhotoViewController:
@property (strong,readwrite) IBOutlet UIImageView *photoView;
@property (strong,readwrite) UIImage *photo;
+ (PhotoViewController *)sharedInstance;
static PhotoViewController *_self;
+ (PhotoViewController*)sharedInstance
{
if (_self == nil) {
_self = [[super alloc] init];
}
return _self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
photoView.image = photo;
}
所以,當我選擇一個PIC,應用程序顯示黑屏,而不在調試方面的錯誤。怎麼了?
P.S:我使用的是故事板和ARC