所以我在显示YPImagePicker
中的selectedImage时遇到问题,我通常不喜欢使用第三方资源,但是图像选择器正是我想要的。无论如何,所选图像不会显示在下一个视图控制器中。我觉得我的代码是正确的,但显然我猜不是。也没有错误。
* **由于下面的配合,将下面的代码编辑为工作代码。
// First VC to open imagePicker
@IBAction func cameraButtonTapped(_ sender: Any) {
let picker = YPImagePicker()
picker.didFinishPicking { [unowned picker] items, cancelled in
if let photo = items.singlePhoto {
let shareVC = self.storyboard?.instantiateViewController(withIdentifier: "SharePhotoController") as! SharePhotoViewController
shareVC.selectedImage = photo.modifiedImage ?? photo.image
picker.pushViewController(shareVC, animated: true)
}
present(picker, animated: false, completion: nil)
//应该显示所选图像的第二个VC的代码
@IBOutlet weak var finalPhoto: UIImageView!
@IBOutlet weak var addCaptionTextField: UITextField!
var selectedImage: UIImage?
override func viewDidLoad() {
super.viewDidLoad()
self.finalPhoto.image = selectedImage
答案 0 :(得分:1)
您将照片分配给您不存在的vc(即sharePostVC
)
picker.dismiss(animated: true) {
if let photo = items.singlePhoto {
let shareVC = self.storyboard?.instantiateViewController(withIdentifier: "SharePhotoController") as! SharePhotoViewController
shareVC.selectedImage = photo.modifiedImage ?? photo.image
self.picker.pushViewController(shareV, animated: true)
}
}
为避免崩溃,请同时移除didSet
部分并将图像分配到viewDidLoad
的{{1}}内的图像视图中