[英]how to pass a UI ImageView from one view controller to another? swift 3
I am trying to pass this UI Image View from one view controller to another on the same storyboard. 我试图将此UI图像视图从一个视图控制器传递到同一情节提要上的另一个视图控制器。 I have already passed a UI TextField to a UI Label and UI Button.
我已经将UI TextField传递给UI标签和UI按钮。 Now I need to do it with a UI Image View.
现在,我需要使用UI图像视图进行操作。
Here are my two view controllers. 这是我的两个视图控制器。
import UIKit
class PhotoShareViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var contentTextView: UITextView!
@IBOutlet weak var thatTextField: UITextField!
@IBOutlet weak var thisTextField: UITextField!
var presenter: PhotoShareModuleInterface!
var image: UIImage!
@IBAction func thisUploadPhoto(_ sender: Any) {
if thisTextField.text != "" && thatTextField.text != ""
{
performSegue(withIdentifier: "segue", sender: nil)
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
var photoShareLabelViewController = segue.destination as! PhotoShareLabelViewController
photoShareLabelViewController.thisString = thisTextField.text!
photoShareLabelViewController.thatString = thatTextField.text!
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
imageView.image = image
}
override var prefersStatusBarHidden: Bool {
return true
}
@IBAction func didTapCancel(_ sender: AnyObject) {
presenter.cancel()
presenter.pop()
}
/* @IBAction func didTapDone(_ sender: AnyObject) {
guard let message = thatTextField.text, !message.isEmpty else {
return
}
guard let messageOne = thisTextField.text, !messageOne.isEmpty else {
return
}
presenter.finish(with: image, content:message)
presenter.dismiss()
}
}
*/
}
extension PhotoShareViewController: PhotoShareViewInterface {
var controller: UIViewController? {
return self
}
}
if someone could tell me how to send the image from one view controller into another that would be awesome! 如果有人可以告诉我如何将图像从一个视图控制器发送到另一个视图控制器,那将非常棒!
You didn't show PhotoShareLabelViewController
, but presumably it has: 您没有显示
PhotoShareLabelViewController
,但是大概它具有:
var thisString: String?
Add 加
var thisImage: UIImage?
And then pass it along the same way as thisString
然后以与
thisString
相同的方式传递它
photoShareLabelViewController.thisImage = imageView.image
And pick it up in the viewDidLoad
of PhotoShareLabelViewController
(which is probably where you pick up thisString
). 并在
PhotoShareLabelViewController
的viewDidLoad
进行拾取(可能是在您拾取thisString
)。 Something like: 就像是:
self.imageView.image = self.thisImage
But, using whatever variable name you are using. 但是,使用您正在使用的任何变量名。
In short, just copy what you are doing for thisString
, but use a UIImage
as the type instead of String
. 简而言之,只需复制您对
thisString
所做的thisString
,但是使用UIImage
作为类型而不是String
。
NOTE: You are not passing a UIImageView from one VC to another (that is impossible). 注意:您没有将UIImageView从一个VC传递到另一个(这是不可能的)。 You are passing the image from an imageview from one VC to another.
您正在将图像从imageview从一个VC传递到另一个VC。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.