カメラで撮影した後アラートを発生させ,画面遷移すると同時に撮影した画像を受け渡したいのですが,画像の受け渡しがうまくいきません。
下記のコードで,画面遷移と同時に,遷移先のImageViewのimageに撮影画像を設定させているつもりなのですが,ImageViewは真っ白でした。
何がいけないのかわからず困っております。どなたかよろしくお願いいたします。
↓撮影画像の保存
swift
1//デリゲート部分を拡張する 2extension CameraViewController:AVCapturePhotoCaptureDelegate{ 3 // 映像をキャプチャする 4 func capture(_ captureOutput: AVCapturePhotoOutput, 5 didFinishProcessingPhotoSampleBuffer photoSampleBuffer: CMSampleBuffer?, 6 previewPhotoSampleBuffer: CMSampleBuffer?, 7 resolvedSettings: AVCaptureResolvedPhotoSettings, 8 bracketSettings: AVCaptureBracketedStillImageSettings?, 9 error: Error?) { 10 11 12 //バッファからjpegのデータを取り出す 13 let photoData = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: photoSampleBuffer!, previewPhotoSampleBuffer: previewPhotoSampleBuffer) 14 //photoDataがnil出ない時UIImageに変換する 15 if let data = photoData { 16 if let stillImage = UIImage(data: data) { 17 //アルバムに追加する 18 UIImageWriteToSavedPhotosAlbum(stillImage, self, nil, nil) 19 20 //画像選択のためのアラートを作成 21 let alert = UIAlertController(title: nil, message: "この画像を使用しますか?", preferredStyle: .alert) 22 //アラートにボタンをつける 23 alert.addAction(UIAlertAction(title: "YES", style: .default, handler: { action in 24 //画面を切り替える 25 let storyboard: UIStoryboard = self.storyboard! 26 let nextView = storyboard.instantiateViewController(withIdentifier: "next") as! NextViewController 27 nextView.PhotoView.image = stillImage 28 self.present(nextView, animated: true, completion: nil) 29 })) 30 alert.addAction(UIAlertAction(title: "NO", style: .cancel, handler: { action in 31 32 })) 33 //アラートを表示 34 self.present(alert, animated: true, completion: nil) 35 36 37 38 } 39 } 40 } 41}
↓遷移先
import UIKit class NextViewController: UIViewController { //UI部品を関連付け @IBOutlet weak var PhotoView: UIImageView! override func viewDidLoad() { super.viewDidLoad()

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/19 07:12
2018/01/19 08:23
2018/01/19 09:36 編集
2018/01/19 09:54