1

我正在使用 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];
    }
}

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

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

4

1 回答 1

1

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

例如,参见ORKCatalog's中的实现TaskListViewController.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)
}
于 2016-03-22T13:19:31.910 回答