【问题标题】:Unexpected non-void return value in tableview表视图中意外的非空返回值
【发布时间】:2017-12-05 00:15:00
【问题描述】:

我有一个 tableview 控制器,我正在为 tableview 注册两个单元格。根据数据库中的数据将决定为 tableView 的每一行注册哪个单元格。但是我的类中有一个指针,我用来从另一个类中获取数据,我必须先获取数据,然后才能确定使用哪个单元格,并且我拥有的代码在一个 void 函数中,我现在无法返回细胞。这是我的代码。当我尝试在下面的代码中返回 CellOne 和 cellTwo 时,我收到此错误“Unexpected non-void return value in void function”

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath, object: PFObject?) -> PFTableViewCell? {
    let CellOne = tableView.dequeueReusableCell(withIdentifier: "Cellone", for: indexPath as IndexPath) as! CellOne
    let CellTwo = tableView.dequeueReusableCell(withIdentifier: "CellTwo", for: indexPath as IndexPath) as! CellTwo

    let CellObject = object?["Home"] as? PFObject
    CellObject?.fetchIfNeededInBackground(block: { (cellsObject, error) in
        if error == nil{
            if cellsObject?["CellType"] as? String == "land"{
                return CellOne
            }else{
                return CellTwo
            }
        }else{

        }
    })
}

【问题讨论】:

  • cellForRow(at:) 来不及获取数据。您需要事先获取数据,以便您可以快速简单地返回正确的单元格。您当前正试图从闭包中返回一个单元格。除了闭包是一个 void return 之外,它也是异步完成的

标签: ios swift xcode parse-platform swift3


【解决方案1】:

在加载 tableview 之前尝试将条件放入函数中,创建一个变量来获取值 true 或 false,并在 tableview 中确保它为 true 打开 cellOne else cellTwo

【讨论】:

    【解决方案2】:

    你没有从函数返回任何东西,你是从一个 close 中返回一个单元格,但是函数完成时没有返回任何东西。

    【讨论】:

      猜你喜欢
      • 2016-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多