繁体   English   中英

ResearchKit 取消按钮不起作用

[英]ResearchKit Cancel button not working

我正在使用 ResearchKit 处理一个项目(Swift),但我的“取消”栏按钮不起作用。 我发现以下方法应该可以使它工作

- (void)setCancelButtonItem:(UIBarButtonItem *)cancelButtonItem {
    [super setCancelButtonItem:cancelButtonItem];
    [cancelButtonItem setTarget:self];
    [cancelButtonItem setAction:@selector(cancelButtonHandler:)];
}
- (void)cancelButtonHandler:(id)sender {
    STRONGTYPE(self.taskViewController.delegate) strongDelegate = self.taskViewController.delegate;
    if ([strongDelegate respondsToSelector:@selector(taskViewController:didFinishWithReason:error:)]) {
        [strongDelegate taskViewController:self.taskViewController didFinishWithReason:ORKTaskViewControllerFinishReasonDiscarded error:nil];
    }
}

我收到“放弃结果”和“取消”弹出窗口,但当我点击“放弃结果”选项时没有任何反应。

我应该检查其他东西吗? 我应该将它连接到某个地方吗?

单击该按钮应调用任务视图控制器委托中taskViewController(taskViewController: ORKTaskViewController, didFinishWithReason reason: ORKTaskViewControllerFinishReason, error: NSError?)方法。 您必须在那里手动关闭任务视图控制器

例如,参见ORKCatalogTaskListViewController.swift

func taskViewController(taskViewController: ORKTaskViewController, didFinishWithReason reason: ORKTaskViewControllerFinishReason, error: NSError?) {
    /*
        The `reason` passed to this method indicates why the task view
        controller finished: Did the user cancel, save, or actually complete
        the task; or was there an error?

        The actual result of the task is on the `result` property of the task
        view controller.
    */
    taskResultFinishedCompletionHandler?(taskViewController.result)

    taskViewController.dismissViewControllerAnimated(true, completion: nil)
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM