PerformSegueWithIdentifier不起作用 [英] PerformSegueWithIdentifier does not work

查看:388
本文介绍了PerformSegueWithIdentifier不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 self.performSegueWithIdentifier 在远程加载JSON文件时更改Storyboard上的视图。为此,我使用Swift类Agent来执行HTTP请求。当我写

I am trying to use use self.performSegueWithIdentifier to change the view on the Storyboard when a JSON file loaded remotely. For this I am using the Swift Class "Agent" to perform the HTTP request. Everything is working when I write the

self.performSegueWithIdentifier("toView2", sender: self)

超出完成变量。为什么不起作用?我想这与发件人:自我有关。但我不知道如何解决这个问题。我在Xcode上没有任何错误。它只是从我的服务器加载数据然后没有任何反应......

out of the "done" variable. Why is it not working? I guess it has something to do with the "sender: self". But I don't know how to solve this. I don't get any errors on Xcode. It just loads the data from my server and then nothing happens...

    @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)
}


推荐答案

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

Edited: (I've put a slightly different answer in the first place)

基本上,问题是你已经进入了一个副队列

Basically, the problem is that you have entered a side queue

并且通过获取主队列并调用其中的segue,它将工作得很好。

and by just getting the main queue and invoking the segue in it, it will work quite fine.

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

希望它有效

这篇关于PerformSegueWithIdentifier不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆