Ios 如何在swift中创建UITableView

Ios 如何在swift中创建UITableView,ios,xcode,uitableview,swift,Ios,Xcode,Uitableview,Swift,我正在尝试在Swift中创建UITableView。我遵循了一个教程,但是表没有我尝试在代码中输入的值。代码如下: class settingsVC2: UIViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet var tableView: UITableView! var items: [String] = ["We", "Heart", "Swift"] override fun

我正在尝试在Swift中创建
UITableView
。我遵循了一个教程,但是
没有我尝试在代码中输入的值。代码如下:

class settingsVC2: UIViewController, UITableViewDataSource, UITableViewDelegate {
    @IBOutlet var tableView: UITableView!
    var items: [String] = ["We", "Heart", "Swift"]

    override func viewDidLoad() {
        super.viewDidLoad()

        self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.items.count;
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell

        cell.textLabel?.text = self.items[indexPath.row]

        return cell
    }

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        println("You selected cell #\(indexPath.row)!")
    }
}

必须将表(委托和数据源)连接到ViewController本身

或者,可以通过编程方式将以下行添加到
viewDidLoad()


必须将表(委托和数据源)连接到ViewController本身

或者,可以通过编程方式将以下行添加到
viewDidLoad()


你跑步时看到了什么是否设置了委托和数据源?我在视图上放置了一个空表,并将其连接到插座。我只看到那张空桌子。这就是我为该视图提供的所有代码。运行时您看到了什么是否设置了委托和数据源?我在视图上放置了一个空表,并将其连接到插座。我只看到那张空桌子。这就是我对该视图的所有代码。
    self.tableView.dataSource = self
    self.tableView.delegate = self