I use swift add an UITableview (without storyboard), but an error happened , I don't why
The error is
2015-06-26 11:08:14.149 test[62289:4994907] *** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-3347.44/UITableView.m:6245
2015-06-26 11:08:14.152 test[62289:4994907] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier TextCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
I don't know how to figure it out
The source is :
import UIKit
class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {
let swiftBlogs = ["a","b","c","d"]
let textCellIndetifier = "TextCell"
var t = UITableView()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
t.frame = self.view.frame
self.view.addSubview(t)
t.delegate = self
t.dataSource = self
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return swiftBlogs.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = t.dequeueReusableCellWithIdentifier(textCellIndetifier, forIndexPath: indexPath) as! UITableViewCell
let row = indexPath.row
cell.textLabel?.text = swiftBlogs[row]
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
t.deselectRowAtIndexPath(indexPath, animated: true)
let row = indexPath.row
println(swiftBlogs[row])
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}