-3

I'm trying to present an array of names into cells of tableview controller.

Here's the code:

import UIKit

class TableViewController: UITableViewController 
{

    var names = ["aA", "aB", "cC"]

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

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


    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
        let cell = tableView.dequeueReusableCellWithIdentifier("MyCell", forIndexPath: indexPath)
        cell.detailTextLabel!.text = names[indexPath.row]
        return cell
    }
} 

When I simulate it, nothing has appeared into the cells! As in the image here

What's wrong with my Code! The compiler did not give me any errors.

nhgrif
  • 61,578
  • 25
  • 134
  • 173
Mariah
  • 573
  • 3
  • 10
  • 26

1 Answers1

2

Update number of sections. Your problem will be solved.

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}
nhgrif
  • 61,578
  • 25
  • 134
  • 173
Payal Maniyar
  • 4,293
  • 3
  • 25
  • 51