我在UITableViewController中创建表视图时遇到问题。行数返回非零数字,并且在故事板中设置高度。但cellForRowAt
从未被调用。swift - cellForRowAt从不叫
下面是代码:
的ViewController:
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "articleCell", for: indexPath) as! ArticleCell
cell.title.text = "THIS IS A TESTE"
cell.desc.text = "THIS IS A TESTE"
return cell
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
有什么不对我的代码?
您是否已将代表和数据源连接到控制器? –