0

以下代码部分工作。它显示问题的步骤和形式。用户能够输入数据,但是当用户单击完成时,什么都没有保存到护理商店并且显示没有更新。任何想法?

class SymptomsVC1: UIViewController{


fileprivate let carePlanStoreManager = CarePlanStoreManager1.sharedCarePlanStoreManager
fileprivate let carePlanData: CarePlanData
fileprivate var symptomTrackerViewController: OCKSymptomTrackerViewController? = nil



required init?(coder aDecoder: NSCoder) {
    carePlanData = CarePlanData(carePlanStore: carePlanStoreManager.store)

    super.init(coder: aDecoder)

}



override func viewDidLoad() {
    super.viewDidLoad()
    setViewControllerTitle(self, title: "Symptoms Card")
    //creatMenuObject(self)


    let symptomTracker = OCKSymptomTrackerViewController.init(carePlanStore: carePlanStoreManager.store)
    symptomTracker.progressRingTintColor = UIColor.magenta
    symptomTracker.delegate = self
    symptomTracker.showEdgeIndicators = true
    // Setup the controller's title
    symptomTracker.title = NSLocalizedString("Symptoms Card", comment: "")

    //change left navigation "Back" button to menu button
    var backImage:UIImage = UIImage(named: "menu")!
    backImage = backImage.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
    let fakeBackButton = UIBarButtonItem(image: backImage, style: UIBarButtonItemStyle.bordered, target: symptomTracker.revealViewController(), action: #selector(SWRevealViewController.revealToggle(_:)))
    symptomTracker.navigationItem.leftBarButtonItem = fakeBackButton;

    self.navigationController?.pushViewController(symptomTracker, animated: true)


}



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


extension SymptomsVC1: OCKSymptomTrackerViewControllerDelegate {

  func symptomTrackerViewController(_ viewController:    OCKSymptomTrackerViewController, didSelectRowWithAssessmentEvent assessmentEvent: OCKCarePlanEvent) {

if viewController.progressRingTintColor == UIColor.magenta {

    guard let userInfo = assessmentEvent.activity.userInfo,
        let task: ORKTask = userInfo["ORKTask"] as? ORKTask else { return }

    let taskViewController = ORKTaskViewController(task: task, taskRun: nil)
    taskViewController.delegate = self

    present(taskViewController, animated: true, completion: nil)


     }
  }
}

extension SymptomsVC1: ORKTaskViewControllerDelegate {

func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith
reason: ORKTaskViewControllerFinishReason, error: Error?) {

defer {
    dismiss(animated: true, completion: nil)
}
print("task view controller clicked")
guard reason == .completed else { return }
guard let symptomTrackerViewController = symptomTrackerViewController,
      let event = symptomTrackerViewController.lastSelectedAssessmentEvent else { return }

let carePlanResult = carePlanStoreManager.buildCarePlanResultFrom(taskResult: taskViewController.result)
print("care plan result")
print(carePlanResult)
carePlanStoreManager.store.update(event, with: carePlanResult, state: .completed) {
    success, _, error in
    if !success {
        print(error?.localizedDescription)
    }
  }
 }
}
4

1 回答 1

0

我通过在以下函数中添加一行代码找到了解决方法:

override func viewDidLoad() {
super.viewDidLoad()
setViewControllerTitle(self, title: "Symptoms Card")
//creatMenuObject(self)


let symptomTracker = OCKSymptomTrackerViewController.init(carePlanStore: carePlanStoreManager.store)
symptomTracker.progressRingTintColor = UIColor.magenta
symptomTracker.delegate = self
symptomTracker.showEdgeIndicators = true
// Setup the controller's title
symptomTracker.title = NSLocalizedString("Symptoms Card", comment: "")

//*** add the following line, now the result show up in carestore ***
symptomTrackerViewController = symptomTracker 


//change left navigation "Back" button to menu button
var backImage:UIImage = UIImage(named: "menu")!
backImage = backImage.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
let fakeBackButton = UIBarButtonItem(image: backImage, style: UIBarButtonItemStyle.bordered, target: symptomTracker.revealViewController(), action: #selector(SWRevealViewController.revealToggle(_:)))
symptomTracker.navigationItem.leftBarButtonItem = fakeBackButton;

self.navigationController?.pushViewController(symptomTracker, animated: true)

}

于 2016-11-15T18:14:06.073 回答