线程 1:使用 IBAction 时发出 SIGABRT 错误信号?

Thread 1: signal SIGABRT error when using IBActions?

我正在尝试使用 this tutorial. 创建项目 我已尽我所能尝试重新创建代码,但遇到了一些问题。这是我的代码:

class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

@IBOutlet var ImageView: UIImageView!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

@IBAction func choosePhoto(sender: AnyObject) {

    let imagePickerController = UIImagePickerController()
    imagePickerController.delegate = self

    let actionSheet = UIAlertController(title: "Choose image source", message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)

    actionSheet.addAction(UIAlertAction(title: "Camera roll", style: UIAlertActionStyle.Default, handler: { ( alert: UIAlertAction!) -> Void in
        imagePickerController.sourceType = UIImagePickerControllerSourceType.Camera
        self.presentViewController(imagePickerController, animated: true, completion: nil)
    } ))

    actionSheet.addAction(UIAlertAction(title: "Take Photo", style: UIAlertActionStyle.Default, handler: { ( alert: UIAlertAction!) -> Void in
        imagePickerController.sourceType = UIImagePickerControllerSourceType.Camera
        self.presentViewController(imagePickerController, animated: true, completion: nil)
    } ))

    actionSheet.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil))

    self.presentViewController(actionSheet, animated: true, completion: nil)

}

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
    let image: UIImage = info[UIImagePickerControllerOriginalImage] as UIImage
    ImageView.image = image
    picker.dismissViewControllerAnimated(true, completion: nil)
}

@IBAction func applyFilter(sender: AnyObject) {

    applyFilterWithName("CIPhotoEffectMono")


}

func applyFilterWithName(filterName: String){
    let originlOrientation = ImageView.image!.imageOrientation
    let originalScale = ImageView.image!.scale

    let inputImage = CIImage(image : ImageView.image)
    let drawingContext = CIContext(options: nil)

    let filterParameters = [kCIInputImageKey: inputImage]

    let filter = CIFilter(name: filterName, withInputParameters: filterParameters)

    let outputImage = filter.outputImage

    let imageRef = drawingContext.createCGImage(outputImage, fromRect: outputImage.extent())

    ImageView.image = UIImage(CGImage: imageRef, scale: originalScale, orientation: originlOrientation)


}

@IBAction func saveImage(sender: AnyObject) {

    UIImageWriteToSavedPhotosAlbum(ImageView.image, nil, nil, nil)

}

我知道这是我必须查看的调试器输出的主要部分:

Image Filter[20320:1554357] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Source type 1 not available'

我似乎无法弄清楚这个错误在哪里或如何修复它。再一次,我尽我所能重新创建代码,但可能会有错误。

如有任何建议或意见,我们将不胜感激。

提前致谢。

你的代码毫无意义。你是说:

actionSheet.addAction(UIAlertAction(title: "Camera roll", style: UIAlertActionStyle.Default, handler: { ( alert: UIAlertAction!) -> Void in
    imagePickerController.sourceType = UIImagePickerControllerSourceType.Camera
    self.presentViewController(imagePickerController, animated: true, completion: nil)
} ))

如果用户要点击 "Camera roll" 按钮,为什么要创建具有 Camera 源类型的图像选择器控制器?这不是用户要求的。

顺便说一句,错误只是意味着没有相机。您不会在模拟器中尝试 运行 这段代码,是吗?那也是毫无意义的。摄像头仅存在于设备上 — 带有摄像头的设备