2017-06-12 76 views
0

照片庫的圖像未顯示。 我的應用程序就像是 my app未顯示照片庫的圖像

我在此應用程序的目標是2 points.First的事情是,當我把「PhotoSelect」按鈕,我可以選擇的照片庫的image.Second的事情是在UIImageView的要顯示的圖書館的形象,但這是不能做到的。我可以訪問照片庫,選擇圖片但圖片不顯示。 PhotoController是

import Foundation 
import UIKit 
class PhotoController:UIViewController,UINavigationControllerDelegate,UIImagePickerControllerDelegate{ 

    @IBOutlet weak var myImageView: UIImageView! 

    @IBAction func PhotoSelect(_ sender: Any) { 
     let myPickerController = UIImagePickerController() 
     myPickerController.delegate = self; 
     myPickerController.sourceType = UIImagePickerControllerSourceType.photoLibrary 

     self.present(myPickerController, animated: true, completion: nil) 

    } 

    @IBAction func PhotoSend(_ sender: Any) { 
    } 

    private func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) 

    { 
     myImageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage 

     self.dismiss(animated: true, completion: nil) 

    } 
    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 

     //myImageUploadRequest() 
    } 
    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

    } 

我認爲連接正常,那麼必要的代碼是不是在PhotoController,對吧?但我不知道該代碼添加這個PhotoController.How可以解決這一問題?

+0

是你的應用程序粉碎? –

+0

我不知道暗戀與否 – user8080149

+0

然後運行您的代碼並檢查它 –

回答

0

因爲這個委託方法在Swift 3.1中不推薦使用,所以請使用此方法。

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { 
     let image = info[UIImagePickerControllerOriginalImage] as! UIImage 
     self.myImageView.image = image 
     self.dismiss(animated: true, completion: nil) 
}