ios - 如何关闭 ORKTaskViewController 并呈现我选择的 View Controller ?
<p><p>我花了 24 小时试图找到解决此问题的方法。当用户在我的应用程序上点击注册时,他们必须回答一系列调查问题(我使用 ORKorderedtask(研究工具包)创建的)。完成调查后,我希望显示主页,但是当我测试应用程序并完成调查时,它会直接返回注册页面。这是我的代码:</p>
<p><strong>1.呈现有序的任务 ViewController ;</strong></p>
<pre><code>let registrationTaskViewController = ORKTaskViewController(task:registrationSurvey, taskRun: nil)
registrationTaskViewController.delegate = self
self.present(registrationTaskViewController, animated: true, completion: nil)
</code></pre>
<p><强>2。关闭任务 ViewController (这不起作用);</strong></p>
<pre><code>func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith reason: ORKTaskViewControllerFinishReason, error: Error?) {
self.dismiss(animated: false) {
let home = homePageViewController()
self.present(home, animated: true, completion: nil)
}
</code></pre>
<p>提前致谢。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>如果不知道堆栈中的所有 ViewController,我建议不要关闭您的注册页面 ViewController 。而是在您的注册屏幕顶部显示您的 <code>HomePageViewController</code>。只需将您的委托(delegate)方法更改为:</p>
<pre><code>func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith reason: ORKTaskViewControllerFinishReason, error: Error?) {
let home = homePageViewController()
self.present(home, animated: true, completion: nil)
}
</code></pre>
<p>或者你甚至可以在你提交你的 ORKTaskViewController 之后在完成 block 中显示你的 <code>HomePageViewController</code>。这种方法的好处是,当用户关闭调查时,他们会立即看到 <code>HomePageViewController</code>:</p>
<pre><code>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)
})
</code></pre>
<p>还有几点:</p>
<p>• 类应以大写字母开头(即 HomePageViewController)。这是每个有经验的开发人员都使用的约定,Apple 甚至推荐。</p>
<p>• 最后,我建议使用导航 Controller 来处理这些转换。使用导航 Controller ,您可以使用推送 segues 实现更好的“流程”。只是感觉好多了。</p></p>
<p style="font-size: 20px;">关于ios - 如何关闭 ORKTaskViewController 并呈现我选择的 ViewController ?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/45827130/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/45827130/
</a>
</p>
页:
[1]