线程1:使用IBActions时信号SIGABRT错误? [英] Thread 1: signal SIGABRT error when using IBActions?

查看:259
本文介绍了线程1:使用IBActions时信号SIGABRT错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用本教程创建一个项目。做了最好的我可以尝试重新创建代码,但有一些问题。这是我的代码:

I am trying to create a project using this tutorial. I did the best I could trying to recreate the code but am having some problems. Here is my code:

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)

}

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

I know this is the main part of the debugger output I have to look at:

图像过滤器[20320:1554357] ***由于未捕获而终止应用程序异常'NSInvalidArgumentException',原因:'源类型1不可用'

我似乎无法弄清楚这个错误在哪里或如何要解决这个问题。再次,我做了最好的我可以重新创建代码,但可能会有错误。

I can't seem to figure out where this error is or how to fix it. Once again, I did the best I could to recreate the code but there could be errors.

任何建议或输入将不胜感激。

Any suggestions or input would be greatly appreciated.

提前感谢

推荐答案

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

Your code is senseless. You are saying:

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)
} ))

如果用户要点击相机卷按钮,那么为什么要创建一个图像选择器控制器一个相机源类型?这不是用户要求的。

If the user is going to tap a "Camera roll" button, why would you then create an image picker controller with a Camera source type? That isn't what the user asked for.

错误,顺便说一下,只是意味着没有相机。你不是想在模拟器中运行这个代码,是吗?这也是毫无意义的。相机只能存在于设备上 - 带相机的设备

The error, by the way, simply means there is no camera. You are not trying to run this code in the Simulator, are you? That would be senseless too. The camera exists only on a device — a device with a camera.

这篇关于线程1:使用IBActions时信号SIGABRT错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆