写真を撮った後に「写真を使う」をクリックした後に新しいviewControllerに移動したい。しかし、セグは決して実行されません。私は、このsegueを、手動segue経由で2つのviewControllerを接続することによって試みました。私は私のsegueコードはどこにある私のimagePickerController関数でprintステートメントがあります。このプリントステートメントは「写真を使う」をクリックすると印刷されるので、なぜ私のセグが無視されますか?私は "@IBAction func someButton(_sender:UIButton)"内でこの全く同じセグコードを試してみました。どんな助けもありがとう。カメラiOS 10(swift 3)で写真を撮った後に「写真を使う」ボタンをクリックすると、新しいviewControllerにセグを実行します
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)
}
}
多分 '' new "'はあなたのセグの識別子ではありません。 – matt
"@IBAction func someButton(_sender:UIButton)"のような任意のボタンに同じコードを入力すると、それは機能したのです –
"made it" print? – matt