2017-05-14 59 views
0

所以我試圖將圖像從第一頁移動到第二頁。但我的prepare()方法不起作用,我不知道爲什麼.. 我試圖在準備函數之前放置覆蓋,但它表示該函數不覆蓋任何東西,所以我不能。我的prepareForSegue()方法不起作用

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

你應該從VC連接您的賽格瑞並給它一個標識..? –

回答

2

您的命名錯誤。檢查正確的版本in docs。方法定義應該是這樣的:

斯威夫特3:

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

斯威夫特2:

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