【问题标题】:PerformSegueWithIdentifier does not workPerformSegueWithIdentifier 不起作用
【发布时间】: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)
}

【问题讨论】:

  • 是否调用了闭包?

标签: ios swift segue agent


【解决方案1】:

已编辑:(我首先给出了一个稍微不同的答案)

基本上,问题是你进入了侧队列

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

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

希望有效果

【讨论】:

  • 我收到Receiver () has no segue with identifier
猜你喜欢
  • 2012-05-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多