Swift:类AppDelegate中的线程1信号SIGABRT:UIResponder,UIApplicationDelegate

时间:2016-04-28 06:03:11

标签: ios swift swift2

每当我尝试使用show segue打开一个不同的视图控制器时,它会崩溃并出现此错误Swift:类AppDelegate中的线程1信号SIGABRT:UIResponder,UIApplicationDelegate,我不知道原因。

这是我尝试打开的View Controller的代码:

import UIKit
import CoreData

class AddEditVC: UIViewController, NSFetchedResultsControllerDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {


var item : Item? = nil

@IBOutlet weak var itemName: UITextField!
@IBOutlet weak var imageHolder: UIImageView!

 let moc = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext

override func viewDidLoad() {
    super.viewDidLoad()

    if item != nil {
        itemName.text = item?.name
        imageHolder.image = UIImage(data: (item?.image)!)
    }


    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func addImage(sender: AnyObject) {
    let pickerController = UIImagePickerController()
    pickerController.delegate = self
    pickerController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
    pickerController.allowsEditing = true

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

}


@IBAction func addImageFromCamera(sender: AnyObject) {
    let pickerController = UIImagePickerController()
    pickerController.delegate = self
    pickerController.sourceType = UIImagePickerControllerSourceType.Camera
    pickerController.allowsEditing = true

    self.presentViewController(pickerController, animated: true, completion: nil)
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
    self.dismissViewControllerAnimated(true, completion: nil)

    self.imageHolder.image = image
}

@IBAction func saveTapped(sender: AnyObject) {

    if item != nil {
        editItem()
    } else {
        createNewItem()
    }
}

func createNewItem() {

    let entityDescription = NSEntityDescription.entityForName("Item", inManagedObjectContext: moc)
    let item = Item(entity: entityDescription!, insertIntoManagedObjectContext: moc)
    item.name = itemName.text
    item.image = UIImagePNGRepresentation(imageHolder.image!)

    do {
        try moc.save()
    } catch {
        return
    }
}
func editItem () {

    item?.name = itemName.text
    item!.image = UIImagePNGRepresentation(imageHolder.image!)

    do {
        try moc.save()
    } catch {
        return
    }

}

2 个答案:

答案 0 :(得分:2)

如果未在MainStoryboard中分配部分@IBOutlet@IBAction,则会出现此错误。 请检查前面的小圆圈。它们应该是灰色的

答案 1 :(得分:0)

它是Andriy所说的,或者您使用错误的标识符执行了PerformSegueWithIdentifier( name ,nil)。最好添加故事板和屏幕截图原控制器也给出了明确的答案。

祝你好运!