简体   繁体   English

presentViewController之后出现黑屏

[英]Black screen after presentViewController

I got a UIViewController called SecondViewController which loads the photo library using UIImagePickerController. 我有一个名为SecondViewController的UIViewController,它使用UIImagePickerController加载照片库。 When I select a photo, it should present another view controller called PhotoViewController. 当我选择一张照片时,它应该显示另一个名为PhotoViewController的视图控制器。 To pass the image from SecondViewController to PhotoViewController I use a singleton. 要将图像从SecondViewController传递到PhotoViewController,我使用单例。 Here is the code: 这是代码:

SecondViewController: 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: 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;
}

So when I choose a pic, the app shows a black screen without errors in debug area. 因此,当我选择图片时,该应用程序显示黑屏,调试区域中没有错误。 What's wrong? 怎么了?

PS: I'm using Storyboard and ARC PS:我正在使用Storyboard和ARC

Couple things to note: 需要注意的几件事:

  • If PhotoViewController is designed in the storyboard, the way that you are instantiating it in sharedInstance is not correct. 如果PhotoViewController是在情节sharedInstance设计的,则在sharedInstance中实例化它的sharedInstance是不正确的。 It is only creating a plain PhotoViewController with none of the Interface Builder objects created. 它只是创建一个普通的PhotoViewController ,而没有创建任何Interface Builder对象。
    • A better approach here, is to connected the scenes for SecondViewController and PhotoViewController with a manual, modal segue in the storyboard. 在这里,一种更好的方法是将第二SecondViewControllerPhotoViewController的场景与情节SecondViewController的手动模态segue相连接。 Then in, SecondViewController in didFinishPickingMediaWithInfo , set the photo on PhotoViewController and manually trigger the segue. 然后,在didFinishPickingMediaWithInfo中的SecondViewController中,在PhotoViewController上设置照片并手动触发序列。
  • viewDidLoad of PhotoViewController will only be called the first time it's presented, so it's not the right place to set the photo for subsequent launches. PhotoViewController viewDidLoad仅在首次显示时被调用,因此它不是为后续启动设置照片的合适位置。 Consider viewWillAppear 考虑viewWillAppear
  • Confirm that photoView is connected between the property and the Interface Builder element in the storyboard 确认在属性和情节photoView中的Interface Builder元素之间连接了photoView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 presentViewController制作黑屏 - presentViewController makes a black screen iOS presentViewController委托返回黑屏 - iOS presentViewController Delegates Returning Black Screen presentViewController黑屏或IDE中的线程调试 - presentViewController black screen or thread debug in IDE iOS 7 presentViewController显示黑屏和SIGABRT - iOS 7 presentViewController shows black screen and SIGABRT 当presentviewcontroller ios时,标签栏控制器显示黑屏 - Tabbar Controller shows Black screen when presentviewcontroller ios Xcode 5 Storyboard-presentViewController不呈现我现有的Viewcontroller并显示黑屏 - Xcode 5 Storyboard - presentViewController not presenting my existing Viewcontroller and giving black screen presentViewController显示黑页 - presentViewController shows black page 在iOS 7中,随着客户VC过渡,是否可以在presentViewController之后在屏幕上制作“ fromviewcontroller”? - In iOS 7, with customer VC transitioning, is it possible to make “fromviewcontroller” on screen after presentViewController? presentViewController黑色背景而不是透明 - presentViewController black background instead of transparent 通话结束后InteractiveTransition-黑屏 - After call finishInteractiveTransition - black screen
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM