解析表格查看单元格空白

时间:2017-03-22 13:26:34

标签: swift tableview parse-server cells

import UIKit
import Parse

class AmbianceTableViewTableViewController: UITableViewController,                UISearchBarDelegate, UISearchDisplayDelegate{
    //variables
    var name = [String]()
    var carBrand = [String]()
    var carEngine = [String]()

    //Properties
    @IBOutlet var searchBar: UISearchBar!

    override func viewDidLoad() {
        super.viewDidLoad()

        //Query data for Table
        tableView.delegate = self
        tableView.dataSource = self

        let query = PFQuery(className: "Make")
        query.findObjectsInBackground(block: { (objects, error) in
            if error != nil {
                print(error)
            }else{
                if let make = objects {
                    for objects in make {
                        if let make = objects as? PFObject {
                            let name = make["name"] as! String

                            print(make["name"])
                        }
                    }
                }
            }
        })

        self.tableView.reloadData()
    }

    // self.clearsSelectionOnViewWillAppear = false
    // self.navigationItem.rightBarButtonItem = self.editButtonItem()

    // MARK: - Table view data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return name.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Ambiance", for: indexPath) as! ViewControllerTableViewCell

        cell.venueNameLabel.text = name[indexPath.row]

        return cell
    }
}

1 个答案:

答案 0 :(得分:0)

您永远不会向名称数组添加任何内容,因此您的tableView将永远不会显示任何数据。此外,查询完成后,您需要调用reloadData。您当前调用的是异步调用,这意味着您在返回数据之前重新加载表。

将您的查询更改为此

class Exam
{
   List<Student> students;
}