Swift 线程1:使用iActions时信号SIGABRT错误?
我试图创建一个项目使用我尽了最大努力,试图重新创建代码,但有一些问题。这是我的密码:Swift 线程1:使用iActions时信号SIGABRT错误?,swift,debugging,ibaction,Swift,Debugging,Ibaction,我试图创建一个项目使用我尽了最大努力,试图重新创建代码,但有一些问题。这是我的密码: class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { @IBOutlet var ImageView: UIImageView! override func viewDidLoad() { super.viewDidLoad() //
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)
}
我知道这是我必须查看的调试器输出的主要部分:
图像过滤器[20320:1554357]***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“源类型1不可用”
我似乎不知道这个错误在哪里,也不知道如何修复它。再一次,我尽了最大努力重新创建代码,但可能会出现错误
如有任何建议或意见,将不胜感激
提前感谢。您的代码毫无意义。你是说:
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)
} ))
如果用户要点击“摄像头滚动”按钮,那么为什么要创建一个带有摄像头
源类型的图像选择器控制器?这不是用户要求的
顺便说一下,这个错误仅仅意味着没有摄像头。您没有试图在模拟器中运行此代码,是吗?那也毫无意义。摄像机只存在于一个设备上——一个带有摄像机的设备。我在模拟器上运行这个。现在这很有道理。我以为模拟器有摄像头是出于愚蠢的原因。谢谢你的回答。它解决了这个问题