Swift:不能调用没有参数的“reloadData”

我目前正在Swift中构build我的第一个应用程序。 我使用Parse作为数据库,并希望显示表食谱中的所有标题。 我为所有的标题创build了一个数组,每次添加一个标题。 但我的tableView函数不会更新它(计数= 0)

我认为这是因为我没有重新加载tableView后,我的数组追加标题。 但是,如果我添加self.tableView.reloadData() – >无法调用'reloadData'没有参数,我得到一个错误。

有人可以帮我吗? 我尝试了很多东西,到处都是互联网,但是找不到答案。

我的代码:

 import UIKit import Parse import Bolts class FirstViewController: UIViewController, UITableViewDelegate { var titel = [String]() var afbeelding = [UIImage]() var afbeeldingFile = [PFFile]() override func viewDidLoad() { super.viewDidLoad() var query = PFQuery(className:"Recipes") query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) -> Void in if error == nil { // The find succeeded. println("Successfully retrieved \(objects!.count) scores.") // Do something with the found objects if let objects = objects as? [PFObject] { for object in objects { self.titel.append((object["titel"] as! String?)!) println(self.titel) self.tableView.reloadData() //THIS GIVES AN ERROR - Cannot invoke 'reloadData' with no arguments } } } else { // Log details of the failure println("Error: \(error!) \(error!.userInfo!)") } } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return titel.count } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! Cell cell.gerechtTitel.text = titel[indexPath.row] return cell } } 

希望你们能帮助我:)

该错误消息是误导,但问题是您的FirstViewController没有tableView属性。

大多数情况下,您希望FirstViewControllerUITableViewController而不是UIViewControllerinheritance。 这将解决问题,因为UITableViewController 一个tableView属性。