2017-03-07 192 views
0

呈現的UIImagePickerController有我的故事板的該部分:從模態視圖控制器

enter image description here

所以我想從UserProfileController存在:UIViewController的 「Мойпрофиль」,這是模態,(關於圖像的頂部)UIImageViewController。

我的代碼:

extension UserProfileController: UIImagePickerControllerDelegate, UINavigationControllerDelegate { 
    @IBAction func imagePressed(_ sender: Any) { 
     let imagePickerController = UIImagePickerController() 
     imagePickerController.delegate = self 
     self.present(imagePickerController, animated: true, completion: nil) 
    } 

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { 
     guard let image = info[UIImagePickerControllerOriginalImage] as? UIImage else { 
      return 
     } 
     picker.dismiss(animated: true, completion: nil) 
     userProfileImageView.image = image 
    } 
} 

好,imagePickerController呈現,但我選擇圖片後,我已經被解僱兩個控制器(imagePickerController和家長 - UserProfileControler)。

我在做什麼錯?謝謝

P.S.可能是問題是我顯示「SideMenuNavigationController」爲模態? (SideMenu框架文檔中,以便決定)

+0

可以嘗試把@IBAction擴展之外? – Adolfo

+0

已經做到了,IBAction與imagePicker相同:didFinish方法在聲明類體 – zzheads

回答

0

嘗試創建了你上課的UIImagePickerController引用(作爲一個變量)

// to choose an image from the Camera Roll 
    fileprivate lazy var imagePicker: UIImagePickerController = { 
     let picker: UIImagePickerController = UIImagePickerController() 

     picker.allowsEditing = false 
     picker.sourceType = .savedPhotosAlbum 
     picker.delegate = self 

     return picker 
    }() 
+0

不起作用,解除了兩者 – zzheads