我正在运行以下代码,并且有一个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)
你不需要reloadData()for UITableViewon viewDidLoad()。
连接UITableView dataSource and delegate到UIViewController的referencingOutlets. 就像下面这样,
| 归档时间: |
|
| 查看次数: |
3685 次 |
| 最近记录: |