【问题标题】:Xcode 9 won´t recognize identifier of a TableViewCellXcode 9 无法识别 TableViewCell 的标识符
【发布时间】:2018-01-22 15:32:37
【问题描述】:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell =  companyTableView.dequeueReusableCell(withIdentifier: "cell")
}

我收到此错误:“从未使用过不可变值 'cell' 的初始化;考虑替换为 '_' 的赋值或删除它。”

我使用“cell”作为 TableViewCell 的标识符。我该如何解决?

【问题讨论】:

  • 提到的error是一个警告(黄色)。必须有另一个关于缺少返回值的真正错误(红色)。
  • 添加缺少的return cell 可能会有所帮助。

标签: uitableview swift4 xcode9


【解决方案1】:

错误消息确实说明了一切:您正在为常量 cell 分配一个值,但从不使用该值。

另外,函数tableView(:cellForRowAt:) 被声明为返回一个 UITableViewCell 实例,而你永远不会这样做。

解决这两个问题会导致以下代码:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
    // do stuff with the cell
    return cell
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-20
    • 2020-09-06
    • 2018-05-02
    • 1970-01-01
    • 2016-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多