我正在運行以下代碼,並且UITableView
嵌套在UIViewController
內。代碼應該使用nib
來填充行,但由於某種原因,當加載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
}
}
您是否檢查了您的forCellReuseIdentifier? –
委託和數據源初始化? –
@IBOutlet weak var myTableView:UITableView! { \t didSet { \t \t myTableView.delegate =自 myTableView.dataSource =自 \t} } – Giang