所以我正在尝试将图像从第一页移动到第二页。但是我的 prepare(( 方法不起作用,我不知道为什么..我试图在准备函数之前放置覆盖,但它说该函数没有覆盖任何东西,所以我不能。
import UIKit
class BeginningPage: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var ImageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
// Dismiss the picker if the user canceled.
dismiss(animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
// The info dictionary may contain multiple representations of the image. You want to use the original.
guard let selectedImage = info[UIImagePickerControllerOriginalImage] as? UIImage else {
fatalError("Expected a dictionary containing an image, but was provided the following: (info)")
}
// Set photoImageView to display the selected image.
ImageView.image = selectedImage
// Dismiss the picker.
dismiss(animated: true, completion: nil)
}
//MARK: Action
@IBAction func PressImage(_ sender: UITapGestureRecognizer) {
let imagePickerController = UIImagePickerController()
imagePickerController.sourceType = .photoLibrary
imagePickerController.delegate = self
present(imagePickerController, animated: true, completion: nil)
}
func prepare(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "mySegue" {
if let destination = segue.destination as? ViewController {
destination.text = "123"
destination.image = ImageView.image
destination.LayerImage.image = ImageView.image
}
}
}
}
你的命名是错误的。在文档中检查正确的版本。方法定义应如下所示:
斯威夫特 3:
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
雨燕 2:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)