[英]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?)
方法。 您必須在那里手動關閉任務視圖控制器。
例如,參見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)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.