2017-04-14 6 views
0

i ein Problem bin vor in IOS swift Xcode 8Absturz in Kerndaten Xcode 8

, nachdem ich mein Setup Core Data und bevor ich irgendwelche Junk-Daten in Zweck legen Sie die App die Abruf der Prüfung korrekt funktionieren ohne Absturz führen und keine Daten, aber nachdem ich ein Datum des App Absturz mit unten Nachricht einfügen

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UITableViewCell 0x7f9b26054c00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Deatials. 

hier sind mein Code

// 

import UIKit 
import CoreData 

     // the NSFetchedResultsControllerDelegate needed to start woring in all the function for datacore 

    class MainVC: UIViewController , UITableViewDelegate, UITableViewDataSource,NSFetchedResultsControllerDelegate{ 

// definning the main view the table and the segment. 

@IBOutlet weak var TableView: UITableView! 
@IBOutlet weak var segment: UISegmentedControl! 

// need to difine the NSFetchedResultsController to define the remaining 3 functions for the tableview 
var controller : NSFetchedResultsController<Item>! 

override func viewDidLoad() { 
    super.viewDidLoad() 

    generateTeseData() 
    attemptFetch() 

    TableView.dataSource = self 
    TableView.delegate = self 
} 


// we need to define 3 main fucntions for the table view 

func numberOfSections(in tableView: UITableView) -> Int { 

    if let sections = controller.sections{ 
     return sections.count 
    } 
    return 0 
} 

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 

    // need to difine number of rows in section by NSFetchedResultsController 
    if let sections = controller.sections{ 
     let sectionInfo = sections[section] 
     return sectionInfo.numberOfObjects 
    } 
    return 0 
} 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

    // linking the cell var with the class of itemCell been created in the View Folder 
    let cell = tableView.dequeueReusableCell(withIdentifier: "CellItem", for: indexPath) as! ItemCell 

    // function been created below: 
    configureCell(cell: cell, indexPath: indexPath as NSIndexPath) 
    return cell 
} 


func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
    return 150 
} 

func configureCell (cell:ItemCell, indexPath: NSIndexPath){ 
    let item = controller.object(at: indexPath as IndexPath) 
    cell.ConfigureCellsInCellclass(item: item) 

} 


func attemptFetch() { 
    let fetchrequest:NSFetchRequest<Item> = Item.fetchRequest() 
    let datesort = NSSortDescriptor(key: "created", ascending: false) 
    fetchrequest.sortDescriptors = [datesort] 

    let controller = NSFetchedResultsController(fetchRequest: fetchrequest, managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil) 

    self.controller = controller 

    do{ 
     try controller.performFetch() 

    }catch{ 
     let error = error as NSError 
     print("\(error)") 
    } 

} 

// these two function for the update in the tableview 
func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) { 
    TableView.beginUpdates() 
} 
func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) { 
    TableView.endUpdates() 
} 

//this function to preforme all the functions for the <Data Core> 
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) { 

    switch(type) 
    { 
    case.insert: 
     if let indexpath = newIndexPath { 
      TableView.insertRows(at: [indexpath], with: .fade) 
     } 
     break 

    case.delete: 
     if let indexpath = indexPath{ 
      TableView.deleteRows(at: [indexpath], with: .fade) 
     } 
     break 

    case.update: 
     if let indexpath = indexPath { 
      let cell = TableView.cellForRow(at: indexpath) as! ItemCell 
      configureCell(cell: cell, indexPath: indexPath! as NSIndexPath) 
     } 
     break 
    case.move: 
     if let indexpath = indexPath { 
      TableView.deleteRows(at: [indexpath], with: .fade) 

     } 
     if let indexpath = indexPath { 
      TableView.insertRows(at: [indexpath], with: .fade) 
     } 
     break 
} 
} 

an dieser Stelle des System ohne Absturz Cun wird.210, aber nachdem ich die Insert-Funktion in darunter hinzufügen Anfang Absturz

func generateTeseData(){ 
    let item = Item(context: context) 

    item.title = "IMAC" 
    item.price = 2000 
    item.details = "Soon" 
} 

das ist meine Ansicht Zelle Datei

class ItemCell: UITableViewCell { 


// this view to take all the label from the view and link it here 


@IBOutlet weak var thump: UIImageView! 
@IBOutlet weak var Title: UILabel! 
@IBOutlet weak var Price: UILabel! 
@IBOutlet weak var Deatials: UILabel! 


// using this function to set the values of the items with the labels been linked before in upper section 

func ConfigureCellsInCellclass (item:Item){ 
    Title.text = item.title 
    Price.text = ("$\(item.price)") 
    Deatials.text = item.details 
} 
} 

danke euch im Voraus

+1

Ihr Problem nicht auf Coredata verwandt ist, geht es um Ihre Xib/Storyboards. Sie haben eine schlechte Verbindung mit IBOutlet dort für die 'UILabel'' Deatials'. Suchen Sie in Ihrer bevorzugten Suchmaschine nach 'App beenden wegen der nicht abgefangenen Ausnahme 'NSUnknownKeyException', Grund: '[XXX setValue: forUndefinedKey:]: Diese Klasse ist nicht Schlüsselcodierung-kompatibel für den Schlüssel XXX', wo Sie XXX entfernen, was spezifisch ist zu Ihrem Problem, aber die Lösung ist reproduzierbar. – Larme

+0

Auch korrekte Rechtschreibung ist 'Details' – Alistra

+0

@Larme danke für Antwort ich lösche gerade alle Verbindungen zwischen dem IBOutlet und erstelle es von Anfang an aber stürze noch, ich verbinde das IBOulet mit Ansichtsklasse von der Zellansicht ist dort irgendein spezielles Möglichkeit, dies zu tun – OWA

Antwort

0

Wie @Larme sagt Ihr Problem ist verwandten zu IBOutlet, das nicht mehr in der Klasse widerspiegelt.

Disconnect schlechten Ausgang

enter image description here