Search code examples
swiftresearchkit

How to remove 'cancel button' in a ResearchKit survey


I've made a ResearchKit survey with 11 steps, but I'd like to remove the default cancel button that's on the bottom of every question.

I've come across this command:

stepViewController.cancelButtonItem = nil;

But I can't seem to find the right place for it.

Thanks.


Solution

  • The correct place would be in the delegate callback. The documentation states "The cancel button item is updated during view loading and when the value of the step property is changed, but is safe to set in the taskViewController:stepViewControllerWillAppear: delegate callback."

    And as an example:

    func taskViewController(_ taskViewController: ORKTaskViewController, stepViewControllerWillAppear stepViewController: ORKStepViewController) {
    
        stepViewController.cancelButtonItem = nil
    
    }
    

    That being said, the functionality currently seems to be broken in the most recent version of ResearchKit per these issues on their repo.

    https://github.com/ResearchKit/ResearchKit/issues/1273

    It currently will disable the functionality of the cancel button, but does not correctly remove the button from the ORKNavigationContainer. If you find a solution, please let me know, had the issue posted on their repo as well as a few other places for some time now with no luck.