我有一个tableview控制器和tableview我正在注册两个单元格。根据数据库中的数据将决定哪个单元格将被注册为tableView的每一行。但是我的类中有一个指针,用于从另一个类中获取数据,我必须首先获取数据,然后才能确定使用哪个单元,并且我拥有的代码处于void函数中,并且现在无法返回细胞。这是我的代码。我得到这个错误“在void函数意外的非空返回值”当我尝试将代码加载你的tableview之前返回以下在tableview中意外的非void返回值
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:)'为时太晚而无法获取数据。您需要先取得数据,以便快速简单地返回正确的单元格。您目前正在尝试从闭包中返回一个单元格。除了关闭是无效返回的事实之外,它也是异步完成的 – Paulw11