为什么我的Uitable View不显示我想要显示的内容



我经过的许多教程,我曾经说过我唯一需要显示我想要的数组的代码是:

import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var chatListTableView: UITableView!
var friends = ["Anthony", "Antonio", "Andy"]
override func viewDidLoad() {
    super.viewDidLoad()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return friends.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell : UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "ChatListCell")
    cell.textLabel.text = self.friends[indexPath.row]
    return cell
}  
}

但是,当我运行应用程序时,tableView仍然为空白。我究竟做错了什么?我觉得我缺少一些东西。我要做的就是在tableView中显示数组。

检查查看controller是否是tableview的数据源和委托

正如ACI在他的答案中所说的那样,您必须将表视图的数据源和委托给您的视图控制器。最简单的方法是在接口构建器中。

最新更新