Thiago Monteiro
Thiago Monteiro

Reputation: 680

UIImagePickerControllerSourceType.SavedPhotosAlbum calling a black screen

I need to get an image from user gallery. This works fine with UIImagePickerControllerSourceType.Camera but when I call the UIImagePickerController with UIImagePickerControllerSourceType.SavedPhotosAlbum I get a black image: The black screen got with UIImagePickerControllerSourceType.SavedPhotosAlbum

This is my code:

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        let picker : TGMImagePicker = segue.destinationViewController as TGMImagePicker
        if segue.identifier == "Camera" {
            picker.sourceType = UIImagePickerControllerSourceType.Camera
        } else if segue.identifier == "Library" {
            picker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
        }

        picker.setCaptureBlock { (image) -> Void in
            self.userImageView.image = image
        }
    }

Upvotes: 1

Views: 723

Answers (1)

bkopp
bkopp

Reputation: 498

wow, just when I comment I find a solution. If you're still looking, the key for me was to add the top line initializing the pickercontroller:

if(segue.identifier == "presentCameraPicker"){
        var nextVC = cameraPickerController()
        nextVC = segue.destinationViewController as cameraPickerController
        nextVC.sourceType = UIImagePickerControllerSourceType.Camera
}else if(segue.identifier == "presentPhotoPicker"){
       var nextVC = cameraPickerController()
        nextVC = segue.destinationViewController as cameraPickerController
        nextVC.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
}

Note that I'm using two different segues to the same view controller in my storyboard.. the one for the camerapicker is a modal presentation, the one for the photopicker is a popover.

Upvotes: 1

Related Questions