[英]How do I dismiss an ORKTaskViewController and present a view controller of my choice?
我已經花了24小時試圖找到解決此問題的方法。 當用戶點擊我的應用程序上的注冊時,他們將不得不回答一系列調查問題(我使用ORKorderedtask(研究工具包)創建了這些問題)。 調查完成后,我希望顯示主頁,但是當我測試應用程序並完成調查后,它將直接返回注冊頁面。 這是我的代碼:
1.展示訂購的任務視圖控制器;
let registrationTaskViewController = ORKTaskViewController(task: registrationSurvey, taskRun: nil)
registrationTaskViewController.delegate = self
self.present(registrationTaskViewController, animated: true, completion: nil)
2.關閉任務視圖控制器(這不起作用);
func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith reason: ORKTaskViewControllerFinishReason, error: Error?) {
self.dismiss(animated: false) {
let home = homePageViewController()
self.present(home, animated: true, completion: nil)
}
提前致謝。
在不了解堆棧中所有ViewController的情況下,建議不要關閉您的注冊頁面視圖控制器。 而是在“注冊”屏幕頂部顯示HomePageViewController
。 只需將您的委托方法更改為此:
func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith reason: ORKTaskViewControllerFinishReason, error: Error?) {
let home = homePageViewController()
self.present(home, animated: true, completion: nil)
}
或者,您甚至可以在執行ORKTaskViewController之后在完成塊中顯示HomePageViewController
。 這種方法的好處是,當用戶關閉調查時,他們將立即看到HomePageViewController
:
let registrationTaskViewController = ORKTaskViewController(task: registrationSurvey, taskRun: nil)
registrationTaskViewController.delegate = self
self.present(registrationTaskViewController, animated: true, completion: {
let home = homePageViewController()
self.present(home, animated: true, completion: nil)
})
還有兩點:
•類應以大寫字母開頭(即HomePageViewController)。 每個經驗豐富的開發人員都使用該約定,Apple甚至建議這樣做。
•最終,我建議使用導航控制器來處理這些過渡。 借助Nav控制器,您可以使用推送選擇功能實現更好的“流程”。 感覺好多了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.