【发布时间】:2017-02-16 15:22:50
【问题描述】:
我正在发送一个 HTTP 请求。如果结果成功,我希望它显示在第二个 UIViewController 上。但是,如果失败,我想在原始 UIViewController 上显示失败。
let parameters: Parameters = [
"x": 2,
"y": 2
]
Alamofire.request(url, method: .post, parameters: parameters, encoding: URLEncoding.default).responseJSON { response in
if((response.result.value) != nil) {
let secondViewController:SecondViewController = SecondViewController()
self.present(secondViewController, animated: true, completion: nil)
let jsonVar: JSON = JSON(response.result.value!)
secondViewController.jsonDisplayResult.text = "\(jsonVar)"
} else {
self.jsonDisplayError.text = "no response"
}
}
我已经创建了第二个 ViewController 和一个标签来显示结果。我收到此错误:致命错误:在展开可选值 (lldb) 时意外发现 nil。
【问题讨论】:
-
你调用 Alamofire 请求方法的上下文是什么?
-
两个整数作为参数传入。 POST 请求将返回两个整数之和。如果一个整数为 null 则返回 Invalid Response
-
它在哪一行崩溃了?是让 jsonVar: JSON = JSON(response.result.value!) 。如果是这样,因为 response.result.value 是 nil 并且 !表示不为零。
-
它在这一行崩溃:"secondViewController.jsonDisplayResult.text = "(jsonVar)""
-
能否在
secondViewController.jsonDisplayResult.text = "\(jsonVar)"添加断点并上传Debug Navigator的截图?
标签: ios uiviewcontroller swift3 httprequest