gpt4 book ai didi

ios - TableView 单元格不可转换为 Void

转载 作者:行者123 更新时间:2023-11-29 02:19:47 26 4
gpt4 key购买 nike

我在从 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
}

最佳答案

那是因为您要从 sendAsynchronousRequest handler 闭包返回 UITableViewCell。闭包的返回类型为 void

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

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

关于ios - TableView 单元格不可转换为 Void,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28293301/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com