我在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
}
有什麼不對我的代碼?
您是否已將代表和數據源連接到控制器? –