表视图未加载数据

dge*_*s21 1 uitableview swift

我正在运行以下代码,并且有一个UITableView嵌套在UIViewController. 代码应该使用 anib来填充行,但由于某种原因,加载时没有显示任何内容UITableView。下面是与具有UIViewController嵌入的tableview. 有谁知道为什么这可能无法加载?

我尝试过的代码:

import UIKit
import Firebase

class Today: UIViewController, UITableViewDelegate, UITableViewDataSource  {

    var anArray: [String] = ["a", "b", "c"]

    @IBOutlet weak var myTableView: UITableView!
    override func viewDidLoad() {

        let nib = UINib.init(nibName: "ScheduleCellTableViewCell", bundle: nil)

        self.myTableView.registerNib(nib, forCellReuseIdentifier: "cell")

        self.myTableView.reloadData() //<<<<<<<<<<<<< RELOADS TABLEVIEW

    }//viewDidLoad() ends here


    public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        //return the count of the number of groups
        return anArray.count
    }


    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! ScheduleCellTableViewCell

        let val = indexPath.row

        cell.testLabel.text = anArray[val]

        return cell
    }

    public func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return 160.0
    }
}
Run Code Online (Sandbox Code Playgroud)

Raj*_*n S 5

你不需要reloadData()for UITableViewon viewDidLoad()

连接UITableView dataSource and delegateUIViewControllerreferencingOutlets. 就像下面这样,

在此输入图像描述