简体   繁体   中英

Unexpected non-void return value in tableview

I have a tableview controller and for the tableview I'm registering two cells. Depending on the data in the database will determine which cell will be registered for each row of the tableView. But there is a pointer in my class I use to fetch data from another class and I have to fetch the data first before I can determine which cell is used and the code I have is in a void function and I'm now having trouble returning the cell. Here is my code. I'm getting this error "Unexpected non-void return value in void function" when I try to return CellOne and cellTwo in the code below

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{

        }
    })
}

在加载表格视图之前,尝试将条件放入函数中,创建一个变量以获取值true或false,然后在表格视图中确保打开true一个cellOne else cellTwo

您没有从函数中返回任何内容,而是从封闭内返回了一个单元格,但是该函数完成后没有返回任何内容。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM