2016-08-10 2 views
1

테이블 뷰에서 저장된 데이터를 업데이트 할 수 없지만 저장된 데이터를 대상 뷰 컨트롤러의 텍스트 필드로 전달할 수 있지만 업데이트 할 수없는 핵심 데이터 문제가 있습니다. 이전 뷰 컨트롤러로 전달합니다. 텍스트 필드에서 편집 할 수는 있지만 데이터가 이전에 저장되었던 이전 테이블보기 컨트롤러의 내용을 업데이트 할 수 없습니다.코어 데이터의 저장된 데이터를 업데이트 할 수 없습니다.

func Plus(sender: AnyObject) { 



     if store == nil 
     { 
      //get the description of the entity 
      let storeDescription = NSEntityDescription.entityForName("Store",inManagedObjectContext: appdelegate.managedObjectContext) 

      //we create managed object to be inserted to core data 
      let store = EventsandnotesStore(entity : storeDescription!,insertIntoManagedObjectContext:appdelegate.managedObjectContext) 
      store.sName = name.text 
      store.sDescription = desc.text 

      let img = UIImage(named: "image.jpg") 
      let imgData = UIImageJPEGRepresentation(img!,1) 
      store.sImage = imgData 
      do { 
       try appdelegate.managedObjectContext.save() 
       self.navigationController?.popViewControllerAnimated(true) 
      } catch let error as NSError { 
       print("Could not save \(error), \(error.userInfo)") 
      } 
     } 
+1

표시중인 코어 데이터 저장은보기 컨트롤러에서 데이터를 표시하는 코드가 아닙니다. 해당 코드를 표시해야합니다. – Daniel

+0

편집 된 텍스트 필드 내용을 핵심 데이터로 업데이트하는 방법을 모릅니다. 아래에 나는 –

+0

에게 다음 뷰 컨트롤러로 데이터를 전달하는 코드를 주었다. 재정의 func prepareForSegue (segue : UIStoryboardSegue, 보낸 사람 : AnyObject?) { if segue.identifier == "show" { v를 = segue.destinationViewController로 설정하십시오! ViewController let indexpath = self.tableView.indexPathForSelectedRow! let row = indexpath.row v.store = stores [행] } 핵심 데이터의 내용을 업데이트하는 코드를 알려주십시오. 나는 신속하고 응용 프로그램 개발에 새로운입니다. –

답변

0

당신은 두 가지

중 하나가 원래 뷰 컨트롤러로 다시 업데이트 된 정보를 전달하는 위임 패턴을 구현 할 수 있습니다. 그런 다음 tableView의 데이터 소스를 수동으로 업데이트 할 수 있습니다.

또는 NSFetchedResultsController을 tableView의 dataSource로 사용하고 delegate 함수를 구현할 수 있습니다. 이를 통해 핵심 데이터가 업데이트되었음을 ​​tableView에 알릴 수 있습니다.

필자는 후반 작업을 권장합니다. 설치하는 데 조금 더 많은 작업이 필요하지만 훨씬 쉽게 사용할 수 있습니다.

+0

마침내 데이터가 업데이트되고 대리자가 엉망이되었습니다. –

관련 문제