1

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)

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.

My code:

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

    }

}

Hope you guys can help me out :)

1 Answer 1

2

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

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.