在我的 Xcode 项目中,我有 主 Storyboard
设置了一个 table view
和一个带有 identifier 的
设置为“单元格”。 TableView 有一个prototype cell
数据源导出
和一个委托(delegate)导出
。
然而,当我在第 11 行创建 TableView 时,由于“未解析的标识符”,我的构建每次都会崩溃(请参见下面的代码)。
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource
{
let array = createArray()
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return(validDeck.count)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
cell = UITableViewCell(style: UITableViewStyle.default, reuseIdentifier: "cell") |"ERROR: Unknown Identifier 'cell' "
cell.textlabel?.text = ""
return cell
}
有没有人知道这个错误并愿意提供帮助?
最佳答案
将下面的代码用于 swift 3.*
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return validDeck.count // assuming count must be greater then 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell
cell.textlabel?.text = "Cell tittle"
return cell
}
关于ios - 创建单元格时 TableViewCell 未解析的标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41520298/