在iOS swift中实现图像选择器时中止有效负载错误

时间:2018-02-05 17:12:57

标签: ios swift xcode uiimagepickercontroller

我今天开始使用swift和Xcode学习iOS开发。我绝对是iOS开发的初学者。现在我正在尝试打开一个图像选择器。但是当我触发事件以打开与UI交互的图像选择器时,它会给我以下错误:

libsystem_kernel.dylib`__abort_with_payload:
    0x1081980a0 <+0>:  movl   $0x2000209, %eax          ; imm = 0x2000209 
    0x1081980a5 <+5>:  movq   %rcx, %r10
    0x1081980a8 <+8>:  syscall 
->  0x1081980aa <+10>: jae    0x1081980b4               ; <+20>
    0x1081980ac <+12>: movq   %rax, %rdi
    0x1081980af <+15>: jmp    0x108191caf               ; cerror_nocancel
    0x1081980b4 <+20>: retq   
    0x1081980b5 <+21>: nop    
    0x1081980b6 <+22>: nop    
    0x1081980b7 <+23>: nop

我完全按照教程进行操作。这是我的代码。

import UIKit

class ViewController: UIViewController, UITextFieldDelegate , UIImagePickerControllerDelegate, UINavigationControllerDelegate{
    @IBOutlet weak var nameTextField: UITextField!
    @IBOutlet weak var mealNameLabel: UILabel!

    @IBOutlet weak var photoImageView: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()

        nameTextField.delegate = self;

        // 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 setDefaultLabelText(_ sender: UIButton) {

    }

    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }

    func textFieldDidEndEditing(_ textField: UITextField) {
        mealNameLabel.text = textField.text;

    }

    @IBAction func selectImageFromPhotoLibrary(_ sender: UITapGestureRecognizer) {
        nameTextField.resignFirstResponder()
        let imagePickerController  = UIImagePickerController()
        imagePickerController.sourceType = .photoLibrary
        imagePickerController.delegate = self
        present(imagePickerController, animated: true, completion: nil)
    }

    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        dismiss(animated: true, completion: nil)
    }

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
            photoImageView.contentMode = .scaleAspectFit
            photoImageView.image = pickedImage
        }

        dismiss(animated: true, completion: nil)

    }
}

单击图像视图打开图像选择器时会引发错误。为什么会抛出这个错误?

0 个答案:

没有答案