Search code examples
uitableviewswift

UITableView method cellForRowAtIndexPath not called


My UITableView isn't showing any data. I think the problem is in:

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell?`

This is my code:

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell? {
    // Configure the cell...
    let cellId: NSString = "Cell"
    var cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellId) as UITableViewCell

    if let ip = indexPath {
        //var data: NSManagedObject = myList[ip.row] as NSManagedObject
        //cell.textLabel.text = data.valueForKey("name") as String
        cell.textLabel.text = "Hi"
    }
    return cell
}

I've seen tutorials on youtube that use this code, but I can't get it to work.

First I fought it was a problem with my array, but when i just put text in it it still doesn't show anything.

I'm running Xcode6 beta 3, but this code did run perfectly fine in beta 2.

I don't have any warning or error messages.

EDIT: I looked up some other Swift projects of me, I got the same function in there and it worked 2 weeks ago but now it also doesn't work. Maybe this is a Xcode6 beta 3 issue?

My class is of type UITableViewController.

EDIT: I was looking through the Apple developer forums and saw related issues after updating to xCode 6 beta 3, so it's likely a problem with xCode 6 beta 3!

EDIT: The method doesn't get called.


Solution

  • Got it!

    Had the same problem - I also have added a tableview into a uiviewcontroller and it also not worked, but I know the problem now.

    If you add the tableview on interface builder AND click after that "Add Missing Constraints", it'll add constraints that can't work together.

    At my position I had the tableview on my whole uiview and after click on "Add Missing Constraints", it will add this here:

    enter image description here

    And now if you delete one of the Trailing or Leading Alignments, it will work - cellforrowatindexPath will get called! Don't know why it is like that, but it will work.

    Hope I can help you.