请在下面的代码中帮助我。我收到了一个错误:
表达式类型“(_,_) - > Void”在没有更多上下文的情况下是不明确的。
import UIKit
import SDWebImage
class CustomImageView: UIImageView {
let progressIndicatorView = CircularLoaderView(frame: CGRect.zero)
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
addSubview(self.progressIndicatorView)
progressIndicatorView.frame = bounds
progressIndicatorView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
let url = NSURL(string: "http://png-3.findicons.com/files/icons/2795/office_2013_hd/2000/word.png")
self.sd_setImage(with: url as URL?, placeholderImage: nil, options: .cacheMemoryOnly, progress: { [weak self] (receivedSize, expectedSize) -> Void in
self.progressIndicatorView.progress = CGFloat(receivedSize)/CGFloat(expectedSize)
}) { [weak self](image, error, _, _) -> Void in
self.progressIndicatorView.reveal()
}
}
}
答案 0 :(得分:1)
将Future<User> getUser(String tag) async {
String base = '/1.1/users/show.json';
final response = await _twitterGet(base, [
["screen_name", tag],
["tweet_mode", "extended"]
]);
if (response.statusCode == 200) {
try {
return User(json.decode(response.body));
} catch (e) {
print(e);
return null;
}
} else {
print("Error retrieving user");
print(response.body);
return null;
}
}
更改为NSURL
应该可以!
答案 1 :(得分:0)
我认为它引用了[weak self] (receivedSize, expectedSize) -> Void in
,这意味着函数sd.setImage()
有多个progress
参数类型。
你可以通过明确地描述receivedSize
和expectedSize
的类型来解决这个问题,就像[weak self] (receivedSize: Type1, expectedSize: Type2) -> Void in
一样。
答案 2 :(得分:0)
因为你缺少来自progressBlock的另外一个参数。检查这个
import UIKit
导入SDWebImage
class CustomImageView:UIImageView { 让progressIndicatorView = CircularLoaderView(frame:CGRect.zero)
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
addSubview(self.progressIndicatorView)
progressIndicatorView.frame = bounds
progressIndicatorView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
let url = URL(string: "http://png-3.findicons.com/files/icons/2795/office_2013_hd/2000/word.png")!
self.sd_setImage(with: url, placeholderImage: nil, options: .cacheMemoryOnly, progress: { (receivedSize, expectedSize, _) in
self.progressIndicatorView.progress = CGFloat(receivedSize)/CGFloat(expectedSize)
}) { (image, error, _, _) in
}
}
}
看到他们应该有三个正在进行中。