2016-05-18 18 views
0

私はプログラミングの初心者です。 CoreDataでは、入力テキストフィールドのデータを編集してコアデータに保存するデータを編集する機能を作成しようとしています。私はfatal errorを持っています:コアデータオブジェクトを編集中に致命的なエラーが発生する

@IBOutlet weak var detailDescriptionLabel: UILabel! 
    @IBOutlet weak var dueDateLabel: UITextField! 
    @IBOutlet weak var value: UITextField! 
    @IBOutlet weak var courseworkname: UITextField! 
    @IBOutlet weak var modulename: UITextField! 
    @IBOutlet weak var level: UITextField! 
    @IBOutlet weak var mark: UITextField! 
    @IBOutlet weak var reminder: UITextField! 
    @IBOutlet weak var notes: UITextField! 

    @IBAction func edit(sender: AnyObject) { 

     modulename.userInteractionEnabled = true 
     modulename.enabled = true 
     dueDateLabel.userInteractionEnabled = true 
     value.userInteractionEnabled = true 
     modulename.userInteractionEnabled = true 
     level.userInteractionEnabled = true 
     mark.userInteractionEnabled = true 
     reminder.userInteractionEnabled = true 
     notes.userInteractionEnabled = true 

     //Interaction 

     value.enabled = true 
     dueDateLabel.enabled = true 
     courseworkname.enabled = true 
     modulename.enabled = true 
     level.enabled = true 
     mark.enabled = true 
     reminder.enabled = true 
     notes.enabled = true 

    } 

    @IBAction func update(sender: AnyObject) { 

    let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate 

     let manageContext = appDelegate.managedObjectContext 

     let fetchRequest = NSFetchRequest(entityName: "Coursework") 

     do { 

      let results = try manageContext.executeFetchRequest(fetchRequest) 


      let attribute = results[0] as! NSManagedObject 

      detailItem?.value = modulename.text 

      attribute.setValue(courseworkname.text, forKey: "courseworkname") 
     attribute.setValue(dueDateLabel.text, forKey: "duedate") 
      attribute.setValue(level.text, forKey: "level") 
       attribute.setValue(mark.text, forKey: "mark") 
       attribute.setValue(modulename.text, forKey: "modulename") 
      attribute.setValue(notes.text, forKey: "notes") 
      attribute.setValue(progressbar.text, forKey: "progressbar") 
       attribute.setValue(reminder.text, forKey: "reminder") 
     attribute.setValue(value.text, forKey: "value") 



     try manageContext.save() 

     }catch let error as NSError{  

     } 

    } 

    var detailItem: Coursework? 
     var detailItem2: Task? 

      { 
     didSet { 
      // Update the view. 
      self.configureView() 
     } 
    } 

    func configureView() { 
     // Update the user interface for the detail item. 
     if let detail = self.detailItem { 
      if let label = self.detailDescriptionLabel { 
       label.text = detail.courseworkname 
      } 
      if let label = self.dueDateLabel { 
       label.text = detail.duedate 
      } 

      if let label = self.value { 
       label.text = detail.value 
      } 

      if let label = self.courseworkname { 
       label.text = detail.courseworkname 
      } 

      if let label = self.modulename { 
       label.text = detail.modulename 
      } 

      if let label = self.level { 
       label.text = detail.level 
      } 

      if let label = self.mark { 
       label.text = detail.mark 
      } 

      if let label = self.reminder{ 
       label.text = detail.reminder 
      } 

      if let label = self.notes{ 
       label.text = detail.notes 

      } 

     } 
+0

このエラーはどの回線で発生しますか? – FredericP

+0

これらの値を取得するために使用している変数やIBOutletを表示できますか? –

+0

フルコードを追加しました。行のattribute.setValue(progressbar.text、forKey: "progress bar")で発生します。-bad executtion –

答えて

0

それは新しい属性である:オプションの値

@IBAction func update(sender: AnyObject) { 
     let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate 

     let manageContext = appDelegate.managedObjectContext 

     let fetchRequest = NSFetchRequest(entityName: "Coursework") 

     do { 

      let results = try manageContext.executeFetchRequest(fetchRequest) 

      let attribute = results[0] as! NSManagedObject 

      detailItem?.value = modulename.text 

      attribute.setValue(courseworkname.text, forkey: "courseworkname") 
      attribute.setValue(dueDateLabel.text, forkey: "duedate") 
      attribute.setValue(level.text, forkey: "level") 
      attribute.setValue(mark.text, forkey: "mark") 
      attribute.setValue(modulename.text, forkey: "modulename") 
      attribute.setValue(notes.text, forkey: "notes") 
      attribute.setValue(progressbar.text, forkey: "progressbar") 
      attribute.setValue(reminder.text, forkey: "reminder") 
      attribute.setValue(value.text, forkey: "value") 

      try manageContext.save() 

      }catch let error as NSError { 
     } 
} 

完全なコードをアンラップながら

が予期せずにnilを見つけ? CoreDataモデルを変更しているときは、アプリケーションをアンインストールしてから再インストールする必要があります。

プログレスバー用にIBOutletが定義されていないことがわかりました。リンクすると機能するはずです。

+0

このURLを確認してください(http://stackoverflow.com/help)コンテンツの品質を上げるのに役立ちます –

関連する問題