gpt4 book ai didi

ios - 任务排序

转载 作者:可可西里 更新时间:2023-11-01 01:28:47 24 4
gpt4 key购买 nike

我想要完成一个任务,然后执行一个 Segue 并转到一个新页面。但出于某种原因,它不执行 Segue,而是在“下载完成”之前打印“我现在在这里”。

class DownloadStocksVC: UIViewController {

var stocks = [Stock]()

override func viewDidLoad() {
super.viewDidLoad()

DataService.ds.REF_BASE.child("stocks").observeEventType(.Value, withBlock: { snapshot in
print(snapshot.value)

if let snapshot = snapshot.children.allObjects as? [FIRDataSnapshot] {
self.stocks = []
for snap in snapshot {

if let stockDict = snap.value as? Dictionary<String, AnyObject> {
let symbol = snap.key
let stock = Stock(stockKey: symbol, dictionary: stockDict)
self.stocks.append(stock)

}
}
}
print("DOWNLOAD DONE")
})

print("I AM HERE NOW")
self.performSegueWithIdentifier("goFromDownloadToTable", sender: nil)

}

最佳答案

您需要在下载完成之后执行 segue,而不是之前。

将对 performSegue 的调用移到完成 block 的末尾。您还需要在主队列上运行。

class DownloadStocksVC: UIViewController {
var stocks = [Stock]()

override func viewDidLoad() {
super.viewDidLoad()
DataService.ds.REF_BASE.child("stocks").observeEventType(.Value, withBlock: { snapshot in
print(snapshot.value)

if let snapshot = snapshot.children.allObjects as? [FIRDataSnapshot] {
self.stocks = []
for snap in snapshot {
if let stockDict = snap.value as? Dictionary<String, AnyObject> {
let symbol = snap.key
let stock = Stock(stockKey: symbol, dictionary: stockDict)
self.stocks.append(stock)

}
}
}

print("DOWNLOAD DONE")
DispatchQueue.main.async {
self.performSegueWithIdentifier("goFromDownloadToTable", sender: nil)
}
})
}

关于ios - 任务排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39988577/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com