swift
1import UIKit 2class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { 3 @IBAction func imagePickerButtonTapped(_ sender: Any) { 4 selectImage() 5 } 6 @IBOutlet weak var imageView: UIImageView! 7 8 override func viewDidLoad() { 9 super.viewDidLoad() 10 // Do any additional setup after loading the view. 11 } 12 13 private func selectImage() { 14 let alertController = UIAlertController(title: "画像を選択", message: nil, preferredStyle: .actionSheet) 15 let cameraAction = UIAlertAction(title: "カメラを起動", style: .default) { (UIAlertAction) -> Void in 16 self.selectFromCamera() 17 } 18 let libraryAction = UIAlertAction(title: "カメラロールから選択", style: .default) { (UIAlertAction) -> Void in 19 self.selectFromLibrary() 20 } 21 let cancelAction = UIAlertAction(title: "キャンセル", style: .cancel) { (UIAlertAction) -> Void in 22 self.dismiss(animated: true, completion: nil) 23 } 24 alertController.addAction(cameraAction) 25 alertController.addAction(libraryAction) 26 alertController.addAction(cancelAction) 27 present(alertController, animated: true, completion: nil) 28 } 29 30 private func selectFromCamera() { 31 if UIImagePickerController.isSourceTypeAvailable(.camera) { 32 let imagePickerController = UIImagePickerController() 33 imagePickerController.delegate = self 34 imagePickerController.sourceType = UIImagePickerControllerSourceType.camera 35 imagePickerController.allowsEditing = true 36 self.present(imagePickerController, animated: true, completion: nil) 37 } else { 38 print("カメラ許可をしていない時の処理") 39 } 40 } 41 42 private func selectFromLibrary() { 43 if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) { 44 let imagePickerController = UIImagePickerController() 45 imagePickerController.delegate = self 46 imagePickerController.sourceType = UIImagePickerControllerSourceType.photoLibrary 47 imagePickerController.allowsEditing = true 48 self.present(imagePickerController, animated: true, completion: nil) 49 } else { 50 print("カメラロール許可をしていない時の処理") 51 } 52 } 53 54 private func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]){ 55 56 if let image = info[UIImagePickerControllerEditedImage] { 57 self.imageView.image = image as? UIImage 58 } 59 60 picker.dismiss(animated: true, completion: nil) 61 } 62 63 override func didReceiveMemoryWarning() { 64 super.didReceiveMemoryWarning() 65 // Dispose of any resources that can be recreated. 66 } 67}
このようなプログラムで、カメラで画像を撮影し、「USe Photo」をタップしてもimageViewに画像が表示されないんですが、なにがいけないんでしょうか?
低レベルな質問で申し訳ないですが、よろしくお願いします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/03/20 09:25
2017/03/20 10:09