我想要用戶在拍攝照片後點擊「使用照片」後進入新的viewController 。但是,賽格從未被執行過。我已經嘗試通過手動連接兩個viewControllers來實現這一功能。我的imagePickerController函數中有一個print語句,這是我的segue代碼的地方。當我點擊「使用照片」時會打印此打印聲明,爲什麼我的細節被忽略?我在「@IBAction func someButton(_sender:UIButton)」中嘗試了完全相同的segue代碼,它工作正常嗎?任何幫助,將不勝感激。當用照相機拍照後點擊「使用照片」按鈕時,執行segue到一個新的viewController iOS 10(swift 3)
這裏是我的代碼:
import UIKit
class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
@IBOutlet weak var imageTake: UIImageView!
var imagePicker: UIImagePickerController!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func takePhoto(_ sender: UIButton) {
imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .camera
present(imagePicker, animated: true, completion: nil)
}
@IBAction func photoLib(_ sender: UIButton) {
imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .photoLibrary
present(imagePicker, animated: true, completion: nil)
}
@IBAction func save(_ sender: AnyObject) {
UIImageWriteToSavedPhotosAlbum(imageTake.image!, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
}
func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
if let error = error {
// we got back an error!
let ac = UIAlertController(title: "Save error", message: error.localizedDescription, preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default))
present(ac, animated: true)
} else {
let ac = UIAlertController(title: "Saved!", message: "Your altered image has been saved to your photos.", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default))
present(ac, animated: true)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
imagePicker.dismiss(animated: true, completion: nil)
imageTake.image = info[UIImagePickerControllerOriginalImage] as? UIImage
print("made it")
performSegue(withIdentifier: "new", sender: self)
}
}
也許''新「'不是你的segue的標識符。 – matt
這是因爲當我把相同的代碼放在像「@IBAction func someButton(_sender:UIButton)」這樣的任意按鈕中時,它的工作原理 –
是否將它「打印出來」? – matt