How to add UItableview without storyboard? (UITableView Error)

I am using the quick add of a UITableview (without a storyboard) but an error has occurred, I don't understand why

Error

2015-06-26 11: 08: 14.149 test [62289: 4994907] *** Approval error at - [UITableView dequeueReusableCellWithIdentifier: forIndexPath:], / SourceCache / UIKit_Sim / UIKit-3347.44 / UITableView.m: 6245

2015-06-26 11: 08: 14.152 test [62289: 4994907] *** The application terminated due to the uncaught exception "NSInternalInconsistencyException", reason: "could not delete the cell with the TextCell identifier - you must register a thread or class for the identifier or connect storyboard cell prototype

I do not know how to understand this

Source:

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.
    }


}
+4
source share
1

, , , UITableViewCell XIB .

override func ViewDidLoad(){
  super.viewDidLoad()
  self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "TextCell")
}
+7

All Articles