【发布时间】:2014-09-18 21:38:10
【问题描述】:
当远程加载 JSON 文件时,我正在尝试使用 self.performSegueWithIdentifier 更改情节提要上的视图。为此,我使用 Swift 类“代理”来执行 HTTP 请求。当我写
self.performSegueWithIdentifier("toView2", sender: self)
退出“完成”变量。为什么它不起作用?我想这与“发件人:自我”有关。但我不知道如何解决这个问题。我在 Xcode 上没有收到任何错误。它只是从我的服务器加载数据,然后什么都没有发生......
@IBAction func goToView2(sender: AnyObject) {
let done = { (response: NSHTTPURLResponse!, data: Agent.Data!, error: NSError!) -> Void in
self.namesJSON = JSONValue(data!)
self.performSegueWithIdentifier("toView2", sender: self)
};
Agent.post("http://api.example.com/test.php", headers: [ "Header": "Value" ],
data: [ "test": "ok" ], done: done)
}
【问题讨论】:
-
是否调用了闭包?