不從服務器加載數據給出錯誤錯誤=(錯誤?)無無。在錯誤發現之前,它看到pfobjects 4值。然後下載並跳動。並指向一行 - 「let detailPrognozS = object [」detailPrognozS「] as!String」。告訴我什麼是錯的?錯誤=(錯誤?)無無快速解析
func detailObject() {
let query = PFQuery(className: "soccer")
query.findObjectsInBackground { (objects:[PFObject]?, error:Error?) in
if error == nil {
for object in objects! {
let detailPrognozS = object["detailPrognozS"] as! String
let detailTitleS = object["detailTitleS"] as! String
let detailTextS = object["detailTextS"] as! String
let imageDetail = object["detailImageS"] as! PFFile
DispatchQueue.main.async { [unowned self] in self.prognozDetail.text = detailPrognozS
self.textView.text = detailTextS
self.titleDetail.text = detailTitleS
}
imageDetail.getDataInBackground(block: { (data:Data?, error:Error?) in
if error == nil {
DispatchQueue.main.async { [unowned self] in
let imageData = data
self.imageDetail.image = UIImage(data: imageData!)
}
}
})
}
}
}
您是力量展開'對象[ 「detailPrognozS」]'。所以如果服務器的有效載荷不包含'detailPrognozS',那麼你的應用程序崩潰。 – Wukerplank