Swift: 无法调用不带参数的 'reloadData'

Swift: Cannot invoke 'reloadData' with no arguments

我目前正在 Swift 中构建我的第一个应用程序。我使用 Parse 作为数据库并希望显示 table 食谱中的所有标题。我为所有标题创建了一个数组,每次都添加一个标题。但是我的 tableView 函数没有更新它 (count = 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 属性.

您很可能希望 FirstViewController 继承自 UITableViewController 而不是 UIViewController。那会解决 问题是因为 UITableViewController 一个 tableView 属性.