gpt4 book ai didi

ios - 在 Swift 中将 ImageView 从一个 View Controller 传输到另一个 View Controller

转载 作者:行者123 更新时间:2023-11-29 02:12:00 24 4
gpt4 key购买 nike

今天下午我一直在 Xcode 中摸索相机应用程序,但遇到了障碍。我希望使用 prepareForSegue 方法将 ImageView 从 Camera 传输到 ViewController。使用我在 Camera 类中的其余代码,我可以成功地将图像显示到 Storyboard上的 ImageView ,所以这不是问题。问题是将它显示到主 ViewController 中的 ImageView 。我在 Storyboard 中正确连接了所有内容。感谢您的帮助!

第一个 View Controller :

class ViewController: UIViewController {

@IBOutlet weak var photoViewData: UIImageView!

}

第二个 View Controller :

class Camera: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

@IBOutlet var imageView:UIImageView!
@IBOutlet var takePictureButton:UIButton!
var moviePlayerController: MPMoviePlayerController?
var image:UIImage?
var movieURL: NSURL?
var lastChosenMediaType: String?

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var destViewController: ViewController = segue.destinationViewController as ViewController

destViewController.photoViewData = imageView
}

最佳答案

我认为在 Controller 之间传递 UIImage 会更好。

class ViewController: UIViewController 
{

strong var photo: UIImage!

override function viewDidLoad()
{
if(self.photo)
self.imageView.image = photo;
}
}

class Camera: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate
{

@IBOutlet var imageView:UIImageView!
@IBOutlet var takePictureButton:UIButton!
var moviePlayerController: MPMoviePlayerController?
var image:UIImage?
var movieURL: NSURL?
var lastChosenMediaType: String?

override func prepareForSegue(segue: UIStoryboardSegue, sender:AnyObject?)
{
var destViewController: ViewController = segue.destinationViewController as ViewController

destViewController.photo = imageView.image
}

关于ios - 在 Swift 中将 ImageView 从一个 View Controller 传输到另一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29186774/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com