以编程方式在swift中加载创建uitableview

use*_*482 9 uitableview ios swift2

我试图在swift中以编程方式创建一个uitableview,但这里没有加载我的代码:

class ViewController: UIViewController, UITableViewDelegate,UITableViewDataSource {
    var tableView: UITableView  =   UITableView()
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.delegate      =   self
        tableView.dataSource    =   self
        tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
        self.view.addSubview(self.tableView)
    }
Run Code Online (Sandbox Code Playgroud)

你们中的任何人都知道我错过了什么或我的代码有什么问题?

我真的很感谢你的帮助.

Zig*_*ong 10

override func viewDidLoad() {
    super.viewDidLoad()
    tableView = UITableView(frame: UIScreen.mainScreen().bounds, style: UITableViewStyle.Plain)
    tableView.delegate      =   self
    tableView.dataSource    =   self
    tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
    self.view.addSubview(self.tableView)
}
Run Code Online (Sandbox Code Playgroud)

tableView = UITableView(frame:UIScreen.mainScreen().bounds,style:UITableViewStyle.Plain)

这行代码将设置您的框架,也是tableview默认框架UITableViewStyle.