ios - 创建单元格时 TableViewCell 未解析的标识符

标签 ios swift xcode uitableview

在我的 Xcode 项目中,我有 主 Storyboard 设置了一个 table view 和一个带有 identifier 的 prototype cell 设置为“单元格”。 TableView 有一个数据源导出和一个委托(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/

相关文章:

ios - 通用链接在 iOS 11.2 中损坏

ios - 带有 AutoLayout 的 UITextField 边框闪烁

iOS:将核心数据提取的结果转换为数组并传递给另一个类

arrays - Swift 3 比较数组索引

swift - 如何使用 Xcode View Controller 上的开关?

ios - 在 RSS iOS 中解析图像

swift - 处理 UrlSession 任务中的 NotConnectedToInternet 错误

arrays - 如何比较两个数组的元素

ios - 没有 id 的 XCODE 协议(protocol)限定符是过时的

ios - Apple - iOS - 使用 XCode 8.2.1 在 iOS 10.3 上进行测试