我创建了两个 View ,然后通过按住 Ctrl 并拖动并创建一个 segue 将一个 View 连接到另一个 View 。给这个 segue 标识符“functionOutput1”
然后我创建了一个函数,并根据函数中的特定输出以编程方式触发上面创建的 segue。
performSegue(withIdentifier: "functionOuput1", sender: self)
View 继续正常,但 View 的内容直到一分钟后才出现。
我还需要在这里做些什么吗?
编辑: 我在 URLRequest 的回调函数中执行这个 segue
let task = session.dataTask(with: request as URLRequest, completionHandler: {
data, response, error -> Void in
if (error != nil) {
// there is an error with the request
print("error: ", error)
} else {
// Request was successful. Check the contents of the response.
print("response: ", response)
let httpResponse = response as! HTTPURLResponse
if httpResponse.statusCode != 200 {
print("problems with server request")
} else {
print("request successful")
//go to next page
performSegue(withIdentifier: "functionOuput1", sender: self)
}
}
})
最佳答案
这可能是线程问题。因为数据是异步返回的。您需要在主线程上运行 View 更新。您可以使用以下代码在 Swift 3.0 中执行此操作:
DispatchQueue.main.async {
// Your view updates here
}
关于swift - 以编程方式触发的 segue 后显示的 View 不会立即更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40229396/