TableView 单元格不可转换为 Void

TableView cell is not convertible to Void

我在从 cellForRowAtIndexPath 方法返回单元格时遇到问题。我一直收到错误 TableViewCell is not convertible to void 这对我来说是个新问题,因为我以前在处理单元格时从未收到过此错误。这是我的 cellForRowAtIndexPath 方法:

 override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject?) -> PFTableViewCell! {
    let cell = tableView.dequeueReusableCellWithIdentifier("CustomCell", forIndexPath: indexPath) as TableViewCell
    cell.userName.text = object?.valueForKey("FBName") as? String
    let userProfilePhotoURLString = object?.valueForKey("pictureURL") as? String

    var pictureURL: NSURL = NSURL(string: userProfilePhotoURLString!)!
    var urlRequest: NSURLRequest = NSURLRequest(URL: pictureURL)
    NSURLConnection.sendAsynchronousRequest(urlRequest, queue: NSOperationQueue.mainQueue()) { (NSURLResponse response, NSData data,NSError error) -> Void in
        if error == nil && data != nil {
            cell.userImage.image = UIImage(data: data)
        }

    cell.ratingsView.show(rating: 4.0, text: nil)

    return cell
}

那是因为您正在 returning UITableViewCell 来自 sendAsynchronousRequest handler 闭包。闭包具有 return 类型 void

您当前在 cellForRowAtIndexPath 中执行异步请求的方法存在缺陷,因为单元将 return 在异步请求完成之前完成。

您应该改为执行异步请求,完成后更新模型,然后重新加载 table 视图。