user3766930 user3766930 - 1 year ago 65
Swift Question

why I don't see any cells in my UITableView in Swift?

I have a

and I put on it

enter image description here

I also added the
to it, checked in story board that my table view has dynamic-generated content and added an identifier "cell" to the
. I connected it with outlets to my class and I set up the inheritance from

class MapViewController: UIViewController, UITableViewDelegate, UITextViewDelegate {

@IBOutlet weak var myTableDetailsPanel: UITableView!

override func viewDidLoad() {
myTableDetailsPanel.delegate = self

Then I add my custom object to my array:

var items = NSMutableArray()
print("size of items before: \(items.count)")
print("size of items after: \(items.count)")
myTableDetailsPanel.hidden = false

I also have this method:

func tableView(myTableDetailsPanel: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = myTableDetailsPanel.dequeueReusableCellWithIdentifier("cell") as! MyDetailsCell
let yawp:MySingleObject = self.items[indexPath.row] as! MySingleObject

And... my problem is that the panel appears empty, in the console I see:

size of items before: 0
size of items after: 1

but somehow I don't see
. My code from
never runs. Why so?

Answer Source

As you implement the UITableViewDelegate protocol to be notified about changes in the UITableView you have to implement the UITableViewDataSource, the data source provides to table-view object with the information it needs to construct and modify a table view.

So you need to implement UITableViewDataSource protocol and declare the dataSource as self like this:

myTableDetailsPanel.dataSource = self

I hope this help you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download