简体   繁体   English

如何将UI ImageView从一个视图控制器传递到另一个? 迅捷3

[英]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 ). 并在PhotoShareLabelViewControllerviewDidLoad进行拾取(可能是在您拾取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.

相关问题 如何将UI图像从一个视图控制器传递到另一个? - How to pass UI image from one view controller to another? 如何将值从一个视图控制器传递给另一个swift? - How to pass value from one view controller to another swift? 使用Firebase将图像从一个视图控制器传递到另一个(swift) - pass an image from one view controller to another (swift) with Firebase 如何将字典从一个视图 controller class 传递到另一个视图?SWIFT - How can I pass dictionary from one view controller class to another?SWIFT 如何在 Swift 中以编程方式从一个控制器导航到另一个视图控制器? - How to navigate from one controller to another View Controller programmatically in Swift? 将json ID从一个表视图控制器传递到Swift 3中的另一个表视图控制器 - pass json id from one table view controller into another table view controller in swift 3 如何在IOS中将数据从一个视图传递到另一个视图控制器? - How to pass data from one view to another view controller in IOS? 如何将数据从一个视图控制器传递到另一个SWIFT - How to pass data from one view controller to the other SWIFT 将图像从集合视图控制器快速传递到另一个视图控制器 - swift pass images from collection view controller to another view controller 如何通过单击按钮在 Swift UI 中从一个视图导航到另一个视图 - How to navigate from one view to another in Swift UI on a click of button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM