0
몇 가지 조사를했는데 실제로 어떤 일이 일어 났는지 이해하지 못합니다.CoreData : 오류 : NSManagedObject 클래스의 지정된 초기화 프로그램을 호출하지 못했습니다.
소원 [1392 : 37721] CoreData : 오류 : 'Wish.ProduitEntity' (lldb) NSManagedObject 클래스의 지정 초기화를 호출하지 못했습니다
나는 테이블보기에서 행을 선택하면 는이 오류가ViewController 클래스의 prepareForSegue 메서드에 오류가 있습니다.
var uneInstanceEntity = ProduitEntity()
것은 직접 인스턴스를 만드는 이유는 도움
import UIKit
import CoreData
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var leTbleView: UITableView!
var arrayProduit = [ProduitEntity]()
var produitSelectionne : ProduitEntity? = nil
override func viewDidLoad() {
super.viewDidLoad()
self.leTbleView.dataSource = self
self.leTbleView.delegate = self
}
override func viewWillAppear(animated: Bool) {
let context = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
let request = NSFetchRequest(entityName: "ProduitEntity")
var ilStock = [AnyObject]?()
do{
try ilStock = context.executeFetchRequest(request)
} catch _ {
}
//put info in the tableView
if ilStock != nil {
arrayProduit = ilStock as! [ProduitEntity]
}
self.leTbleView.reloadData()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arrayProduit.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel!.text = (arrayProduit[indexPath.row]).nom
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
produitSelectionne = self.arrayProduit[indexPath.row]
performSegueWithIdentifier("detailSegue", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "detailSegue" {
let detailVC = segue.destinationViewController as! DetailViewController
detailVC.uneInstanceEntity = self.produitSelectionne!}
}
}
import UIKit
import CoreData
class DetailViewController: UIViewController {
@IBOutlet weak var titleLbl: UILabel!
@IBOutlet weak var storeLbl: UILabel!
@IBOutlet weak var imageProduit: UIImageView!
var uneInstanceEntity = ProduitEntity()
override func viewDidLoad() {
super.viewDidLoad()
self.titleLbl.text = uneInstanceEntity.nom
self.storeLbl.text = uneInstanceEntity.magasin
}
}
import UIKit
import CoreData
class ajouterProduitViewController: UIViewController {
@IBOutlet weak var modelTxtField: UITextField!
@IBOutlet weak var magasinTxtField: UITextField!
@IBOutlet weak var photoImage: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
}
//Add a new product
func sauvegardeProduit() {
let context = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
let objetEntity = NSEntityDescription.insertNewObjectForEntityForName("ProduitEntity", inManagedObjectContext: context) as!ProduitEntity
objetEntity.nom = modelTxtField.text
objetEntity.magasin = magasinTxtField.text
//objetEntity.unVisuel = UIImageJPEGRepresentation(UIImage(named: ""), 1)
do {
try context.save()
} catch _ {
}
}
@IBAction func saveBtn(sender: AnyObject) {
sauvegardeProduit()
self.dismissViewControllerAnimated(true, completion: nil)
}
@IBAction func cnclBtn(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil)
}
}
Wain! 이제는 더 자세히 살펴보고 그곳에서 일어난 일을 이해할 것입니다. – Sylvain