CellForRowAtIndexPath is never called

I have a storyboard that contains UIViewController

which has UITableview

and UITableViewCell

, everything is connected correctly, and I put all the necessary code for the UIViewController.

When I run the app in the simulator, one of the functions of the data source cellForRowAtIndexPath

is never numberOfRowsInSection

anumberOfRowsInSection

  • "func tableView (tableView: UITableView, section numberOfRowsInSection: Int) → Int" is called
  • But "func tableView (tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell" is NEVER CALLED

Below is my code for the 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 anyone suggest why it cellForRowAtIndexPath

never gets called?

+4


source to share


3 answers


Here's what I did, uninstall Xcode 5 and 6 as soon as I reinstalled Xcode 6, Ran project, and WORKED. After 2 days of debugging, reinstalling it, which did the trick.



+3


source


I just checked your code, it works.
Check numberOfRowsInSection

whether numberOfRowsInSection

or not. if not, check the connection in the storyboard .



+2


source


Try it:

MainViewController class: UIViewController, UITableViewDataSource, UITableViewDelegate {

func viewDidLoad () {

super.viewDidLoad ()

tableView.dataSource = self

tableView.delegate = self

}

}

0


source







All Articles