0
我做一個查詢檢索解析一些數據,我有叫行使外部類的查詢,而不是在tableViewController和代碼如下:查詢與分析是太慢
// LOAD
var arrayExercise:[Exercise] = [Exercise]()
func loadAll() -> [Exercise] {
// Esercizio di load
let exerciseName:Exercise = Exercise()
let query = PFQuery(className:"Exercise")
query.whereKey("username", equalTo:(PFUser.currentUser()?.username)!)
query.findObjectsInBackgroundWithBlock {
(objects: [PFObject]?, error: NSError?) -> Void in
if error == nil {
// The find succeeded.
print("Successfully retrieved \(objects!.count) scores.")
// Do something with the found objects
if let objects = objects {
for object in objects {
// Add the name of the Exercise into the array
let text:String? = (object)["name"] as? String
exerciseName.setNome(text!)
self.arrayExercise.append(exerciseName)
}
}
} else {
// Log details of the failure
print("Error: \(error!) \(error!.userInfo)")
}
}
return arrayExercise
}
而在TableViewController中,我在viewDidLoad中調用了這個方法,但是我注意到查詢完成之前的tableView加載並且結果爲空!我試圖將tableView.reloadData()添加到查詢中,但它不起作用!我如何加載查詢,然後顯示tableView?謝謝!
'reloadData'方法通常是正確的方法。 – luk2302
@ luk2302但我在一個外部類,而不是在uitableview上,我怎麼能從另一個類reloadData? –