2

I've spent 24 hours trying to find a solution for this issue. When a user hits register on my app they will have to answer a series of survey questions (which I created using an ORKorderedtask (research kit)). Once the survey is completed I'd like the home page to be presented, however when I test the app and finish the survey it goes straight back to the register page. here's my code:

1.presenting the ordered task view controller;

let registrationTaskViewController = ORKTaskViewController(task:  registrationSurvey, taskRun: nil)
registrationTaskViewController.delegate = self
self.present(registrationTaskViewController, animated: true, completion: nil)

2. Dismissing the task view controller(this doesn't work);

func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith reason: ORKTaskViewControllerFinishReason, error: Error?) {
    self.dismiss(animated: false) {
    let home = homePageViewController()
    self.present(home, animated: true, completion: nil)
}

thanks in advance.

toddg
  • 2,863
  • 2
  • 18
  • 33
  • 1
    What ViewController is `self.dismiss(animated: false)` called from? It seems like you would want to dismiss your `ORKTaskViewController` rather than self, no? – toddg Aug 22 '17 at 21:27
  • The register page view controller. How would I go about doing that? I'm extremely new to Swift building my app from the ground up. – Sarah Stringer Aug 22 '17 at 21:32

1 Answers1

0

Without knowing all the ViewControllers in your stack, I'd suggest not dismissing your register page view controller. Instead present your HomePageViewController on top of your Register screen. Just change your delegate method to this:

func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith reason: ORKTaskViewControllerFinishReason, error: Error?) {
    let home = homePageViewController()
    self.present(home, animated: true, completion: nil)
}

Or you could even present your HomePageViewController in the completion block after you prsent your ORKTaskViewController. The benefit of this approach would be that when the user dismisses the survey, they will see the HomePageViewController immediately:

let registrationTaskViewController = ORKTaskViewController(task:  registrationSurvey, taskRun: nil)
registrationTaskViewController.delegate = self
self.present(registrationTaskViewController, animated: true, completion: {
    let home = homePageViewController()
    self.present(home, animated: true, completion: nil)
})

A couple more points:

• Classes should begin with capital letters (i.e. HomePageViewController). It's a convention that every single experienced developer uses, and Apple even recommends.

• Ultimately, I would suggest using a Navigation Controller to handle these transitions. With Nav Controllers you can achieve a much better 'flow' using push segues. It just feels better.

toddg
  • 2,863
  • 2
  • 18
  • 33
  • Unfortunately none of the solutions are working for me, so frustrating but thank you for your help! I'll take your points onboard, I'm going to take a step back and do a little more research on concepts such as 'Nav controllers' like you suggest and hopefully I can eventually overcome this issue and learn. Thanks again :) – Sarah Stringer Aug 22 '17 at 22:03
  • Hmmm, ok. It might help if you update your question to include more of your code. Are you using Storyboards? – toddg Aug 22 '17 at 22:33
  • Yes I am for the register/ homepage view controllers but not for the ORKTaskViewController if that makes sense? – Sarah Stringer Aug 24 '17 at 06:55