我是iOS开发新手,基本上我试图用数组中的字符串值填充TableView。iOS Swift - TableView行为空
但是,当我运行应用程序时,空白行显示,并没有显示文本值。我有正确的编码吗?
import UIKit
class SelectIssueController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var issuesTableView: UITableView!
var issues = [Issue]()
override func viewDidLoad() {
super.viewDidLoad()
self.issues = ["Test1", "Test2", "Test3"]
self.issuesTableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
}
override var preferredStatusBarStyle: UIStatusBarStyle{
return UIStatusBarStyle.lightContent
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.issues.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.issuesTableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as UITableViewCell
cell.textLabel?.text = issues[indexPath.row]
//Even if I manually set a value, the rows are still blank
//cell.textLabel?.text = "Hello World"
return cell
}
}
你设置你的SelectIssueController实例是UITableView的数据来源? –
您是否在谈论参考插座? @LucasDerraugh如果是这样,是的,我有:) – Dinuka
tableView的dataSource在故事板或问题TableView.datasource = self –