0

Here is the code from my custom cell class:

import UIKit

class CustomOrderTableViewCell: UITableViewCell {

    @IBOutlet var MealName: UILabel!
    @IBOutlet var MealPrice: UILabel!
    @IBOutlet var MealDescription: UILabel!

    override func awakeFromNib() {

        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    @IBAction func deleteMeal(sender: AnyObject) {
    }
}

Here are the table view related functions:

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return mealArray.orderedMeals.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        print("in")
        var cell = tableView.dequeueReusableCellWithIdentifier("orderCell", forIndexPath: indexPath) as! CustomOrderTableViewCell
        cell.MealName.text = mealArray.orderedMeals[indexPath.row].mealName
        cell.MealDescription.text = mealArray.orderedMeals[indexPath.row].mealDescription
        let price = NSString(format: "%.2f", mealArray.orderedMeals[indexPath.row].mealPrice) as String
        cell.MealPrice.text = "R" + price


        return cell
    }

The problem is that nothing gets displayed in the table view and func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell is never called. Any solutions? Thanks

1

1 Answer 1

1

If func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell is never called that means you have not connected your UITableViewDataSource in IB correctly. Make sure that you connect the dataSource property with your ViewController. Also check that all classes are set for your ViewController, TableView and the Cell itself as this another common mistake.

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

1 Comment

No I found the problem, my array was empty

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.