Skip to main content
 首页 » 操作系统

swift之为什么我的进度条不起作用之Swift,Parse,我正在为这个而烦恼

2024年01月01日55kerrycode

let userImageFile = object.valueForKey("profileImage") as PFFile 
     userImageFile.getDataInBackgroundWithBlock { 
        (imageData: NSData!, error: NSError!) -> Void in 
        if error == nil { 
            let image = UIImage(data:imageData) 
 
            cell.parseImage.image = image 
        }, progressBlock: { 
            (percentDone: Int) -> Void in 
            cell.progressView.progress = Float(percentDone)/100 
        } 
 
 
    } 

好的,问题来了。这一行:

}, progressBlock: { 

表示连续的行必须用“;”分隔

说使用未解析的标识符“progressBlock”

说出预期的表达方式

不知道为什么它不允许我。根据 Parse 文档,这是 Swift 进度条的正确语法。我可以正常下载和查看图片,没有进度条。

请您参考如下方法:

您缺少 getDataInBackgroundWithBlock 调用的括号,并且有一些不匹配的括号。试试这个:

userImageFile.getDataInBackgroundWithBlock ( { 
    (imageData: NSData!, error: NSError!) -> Void in 
    if error == nil { 
        let image = UIImage(data:imageData) 
        cell.parseImage.image = image 
    } 
    }, progressBlock: { 
        (percentDone: Int) -> Void in 
        cell.progressView.progress = Float(percentDone)/100 
}) 

或者在 swift 中,您可以将最后一个 block 放在括号之外,删除最后一个参数:

userImageFile.getDataInBackgroundWithBlock ( { 
    (imageData: NSData!, error: NSError!) -> Void in 
    if error == nil { 
        let image = UIImage(data:imageData) 
        cell.parseImage.image = image 
    } 
     }) { 
     (percentDone: Int) -> Void in 
     cell.progressView.progress = Float(percentDone)/100 
}