Swift:无法调用' reloadData'没有参数

时间:2015-06-09 13:17:00

标签: ios swift uitableview tableview

我目前正在Swift中构建我的第一个应用。我使用Parse作为数据库,并希望显示表食谱中的所有标题。我为所有标题创建了一个数组,并且每次都添加一个标题。但是我的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

    }

}

希望你们能帮助我:)

1 个答案:

答案 0 :(得分:2)

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

您很可能希望FirstViewController继承 UITableViewController代替UIViewController。那会解决 问题是因为UITableViewController tableView属性。

相关问题