照片库的图像未显示

时间:2017-06-12 12:39:55

标签: ios swift

未显示照片库的图像。 我的应用就像 my app

我在这个应用程序中的目标是2分。首先,当我放入“PhotoSelect”按钮时,我可以选择照片库的图像。第二件事是在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的代码。如何解决这个问题?

1 个答案:

答案 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)
}