PerformSegueWithIdentifier不起作用

我正在尝试使用self.performSegueWithIdentifier在远程加载JSON文件时更改Storyboard上的视图。 为此,我使用Swift类“Agent”来执行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) } 

编辑:(我首先给出了一个略有不同的答案)

基本上,问题是您已进入旁队列

只需获取主队列并调用其中的segue,它就可以正常工作。

 dispatch_async(dispatch_get_main_queue()) { self.performSegueWithIdentifier("toView2", sender: self) } 

希望它有效