【发布时间】: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