DP2
DP2

Reputation: 625

cellForRowAtIndexPath is never called

I have a storyboard which contains UIViewController which has UITableview and UITableViewCell, everything is hooked up properly and I have put all the required code for UIViewController.

When I run the app in the simulator one of the datasource function cellForRowAtIndexPath is never called but numberOfRowsInSection is called

Below is my code for view controller:

import UIKit

class DVViewController: UIViewController, UITableViewDelegate, UITableViewDataSource
{

    @IBOutlet var tableView : UITableView?
    var tableData = ["Row 1", "Row 2", "Row 3"]
    let kCellID = "cell"

    override func viewDidLoad()
    {
        super.viewDidLoad()

        self.tableView?.delegate = self;
        self.tableView?.dataSource = self;

        //load cell
        self.tableView?.registerClass(UITableViewCell.self, forCellReuseIdentifier: kCellID);
        self.tableView?.reloadData();
    }

    //MARK: Tableview delegates
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {
        return self.tableData.count;
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
       //var cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: kCellID)
        let cell : UITableViewCell = UITableViewCell (style: UITableViewCellStyle.Default, reuseIdentifier: kCellID);
        return cell;
    }
}

Can someone suggest why cellForRowAtIndexPath is never called?

Upvotes: 5

Views: 6212

Answers (3)

Nirbhay Singh
Nirbhay Singh

Reputation: 1298

Try this:

class MainViewController: UIViewController, UITableViewDataSource, UITableViewDelegate{

func viewDidLoad(){

super.viewDidLoad()

tableView.dataSource = self

tableView.delegate = self

}

}

Upvotes: 0

user4007645
user4007645

Reputation:

I have just checked your code, it works.
Check to see whether or not numberOfRowsInSection is called. if not check the connection in storyboard.

Upvotes: 2

DP2
DP2

Reputation: 625

Here is what I did, uninstalled Xcode 5 & 6 both the reinstalled Xcode 6 only, Ran the project and it WORKED. After 2 days of debugging its the reinstall which did the trick.

Upvotes: 3

Related Questions