Swift:不能在没有参数的情况下调用'reloadData' [英] Swift: Cannot invoke 'reloadData' with no arguments

查看:412
本文介绍了Swift:不能在没有参数的情况下调用'reloadData'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm currently building my first app in Swift. I use Parse as database and want to show all the titles in table Recipes. I created an array for all the titles and add every time a title. But my tableView function doesn't update it (count = 0)

我认为这是因为我在向数组附加标题后没有重新加载tableView。但是如果我添加 self.tableView.reloadData() - >无法调用没有参数的'reloadData',我会收到错误。

I think that's because I don't reload the tableView after I append a title to my array. But I get aan error if I add self.tableView.reloadData() --> Cannot invoke 'reloadData' with no arguments.

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

Can someone help me out? I tried so many things and looked everywhere on the internet but couldn't find an answer.

我的代码:

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 property。

The error message is misleading, but the problem is that your FirstViewController does not have a tableView property.

很可能你想从
<$继承 FirstViewController c $ c> UITableViewController 而不是 UIViewController 。这将解决
问题,因为 UITableViewController tableView 属性。

Most probably you want FirstViewController to inherit from UITableViewController instead of UIViewController. That would solve the problem because UITableViewController has a tableView property.

这篇关于Swift:不能在没有参数的情况下调用'reloadData'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆