构建并运行时,我的表为空。我已经验证了与数据库的连接。当我对数据进行硬编码时,它就可以正常工作。我认为我的代码实现不正确,因为这是我第一次使用Parse。
import UIKit
class ListSubViewController: UITableViewController {
var vendorArray : NSMutableArray = []
override func viewDidLoad() {
super.viewDidLoad()
let query = PFQuery (className: "Vendor")
query.order(byAscending: "ID")
query.findObjectsInBackground {
(objects:[PFObject]?, error:Error?) -> Void in
if error == nil {
if let objects = objects {
print("\(objects.count) vendors are listed")
for object in objects {
self.vendorArray.add(object)
}
self.tableView.reloadData()
}
} else {
print("There is an error")
}
}
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.vendorArray.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
let vendorObjects = vendorArray[indexPath.row] as! PFObject
let vendorName = vendorObjects["vendorName"] as! String
let image = vendorObjects["Image"] as! PFFile
cell.vendorLabel.text = vendorName
image.getDataInBackground(block: {
(result, error) in
cell.vendorImage.image = UIImage(data: result!)
})
self.tableView.reloadData()
return cell
}
答案 0 :(得分:0)
放入此行
public event OnServiceReadyHandler OnServiceReady
{
add
{
lock (onServiceReadyHandler) {
if (!IsReady)
onServiceReadyHandler += value;
else
value(this);
}
}
// Remove ...
}
public void Init()
{
// Do stuff
lock (onServiceReadyHandler) {
IsReady = true;
}
OnServiceReady?.Invoke(this);
}
内部self.tableView.reloadData()
会导致递归-无休止的过程,因为每次创建单元时都会重新加载表