我正在使用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];
}
}我得到丢弃结果并取消弹出,但是当我点击“丢弃结果”选项时什么都不会发生。
我要不要检查一下其他的东西?我应该把它连接到什么地方吗?
发布于 2016-03-22 13:19:31
单击该按钮将调用任务视图控制器委托中的taskViewController(taskViewController: ORKTaskViewController, didFinishWithReason reason: ORKTaskViewControllerFinishReason, error: NSError?)方法。您必须手动关闭那里的任务视图控制器。
例如,请参见ORKCatalog的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)
}https://stackoverflow.com/questions/36151504
复制相似问题