我的prepareForSegue()方法不起作用

时间:2017-05-14 16:15:13

标签: swift xcode prepare

所以我试图将图像从第一页移动到第二页。但我的prepare()方法不起作用,我不知道为什么.. 我试图在prepare函数之前放置override,但是它说函数没有覆盖任何东西,所以我不能。

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
         }
      }
   }
}

1 个答案:

答案 0 :(得分:2)

您的命名错误。检查正确的版本in docs。方法定义应如下所示:

斯威夫特3:

override func prepare(for segue: UIStoryboardSegue, sender: Any?)

Swift 2:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)