【发布时间】:2016-03-28 15:07:47
【问题描述】:
我正在使用 ResearchKit 进行一个项目,因此我将用户发送到我创建的任务中:
let taskViewController = ORKTaskViewController(task: SurveyTask, taskRunUUID: nil)
taskViewController.delegate = self
presentViewController(taskViewController, animated: true, completion: nil)
当用户完成调查后,他进入:
func taskViewController(taskViewController: ORKTaskViewController, didFinishWithReason reason: ORKTaskViewControllerFinishReason, error: NSError?) {
switch reason {
case .Completed:
... }
在这里我尝试在之前显示警报时遇到问题
taskViewController.dismissViewControllerAnimated(true, completion: nil)
我收到以下错误:
尝试在 ViewController: ... 上显示 UIAlertController: ... 其视图不在窗口层次结构中
知道如何在关闭 ViewController 之前显示警报吗?
我使用下面的警报:
let alertView = UIAlertController(title: "Houps", message: "Could not connect to the server.", preferredStyle: .Alert)
alertView.addAction(UIAlertAction(title: "Ok", style: .Default, handler: nil))
presentViewController(alertView, animated: true, completion: nil)
编辑: 代码如下:
if let httpResponse = response as? NSHTTPURLResponse {
print("HTTP response: \(httpResponse.statusCode)")
if httpResponse.statusCode == 201 {
taskViewController.dismissViewControllerAnimated(true, completion: nil)
}
} else {
print("No HTTP response")
let alertView = UIAlertController(title: "Houps", message: "Could not connect to the server.", preferredStyle: .Alert)
alertView.addAction(UIAlertAction(title: "Ok", style: .Default, handler: nil))
presentViewController(alertView, animated: true, completion: nil)
}
【问题讨论】:
-
您能否通过单击警报控制器中的“确定”按钮关闭视图控制器?
-
我还不想解散,我首先想在戒备状态下显示。解雇工作得很好。问题是显示警报。
-
是的,@j.f.在警报上点击“确定”时表示要关闭。
-
对,你显示警报,然后当用户单击警报上的“确定”按钮时,关闭视图控制器。
-
我无法显示警报。很抱歉没有更好地解释。我在显示警报时遇到问题。
标签: ios swift alert uialertaction researchkit