I have referred to this question, and tried to implement the various answers. I\'m doing something dumb, as cellForRow is not being called, and I\'m just getting a blank tab
You need to connect Delegate DataSource of TableView, both are connected with the tableview then can only NumberOfRowsInSection and CellForRowAtIndexpath called.
Here is working code. No need to register cell in -viewDidLoad(). Also UITableView is added as subview in Storyboard.
If someone has this kind of requirement.
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.delegate = self
self.tableView.dataSource = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("CELL") as UITableViewCell?
if (cell == nil) {
cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "CELL")
}
cell?.textLabel?.text = NSString(format: "%d", indexPath.row) as String
return cell!
}
}