ios - UIimage 可能无法响应 "setImageWithUrl"iOS

标签 ios uiimage cell

我想在 ImageView 中使用 URL 显示图像。我试过使用这个:

[cell.avatarImageView.image setImageWithURL:[NSURL URLWithString:@"http://www.innovaworks.com/wp-content/themes/innovaworks/images/home_person.png"]];

但它给了我这个警告:

UIImage may not respond to "setImageWithUrl"

并且图像未显示。

最佳答案

UIImage 上没有方法来设置带有 url 的图像。

有关如何根据 url 的数据内容设置图像的完整说明,请参阅此答案:https://stackoverflow.com/a/2782491/209867

要点是:

UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.innovaworks.com/wp-content/themes/innovaworks/images/home_person.png"]]];

了解这是同步 UITableView 中的滚动性能会非常糟糕,您不应该使用它!我只是为了技术准确性和全面性而提供此答案。

您似乎是从某处复制此代码,有许多开源类别将从 url 异步加载图像。

一个这样的开源项目是 SDWebImage。 https://github.com/rs/SDWebImage这是一个广泛使用的项目,可让您轻松地异步从 url 加载 UIImage

关于ios - UIimage 可能无法响应 "setImageWithUrl"iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27126614/

相关文章:

ios - Xcode在源代码中未显示OCMock验证错误

jupyter-notebook - 如何在启动它的单元格中打印 jupyter 后台作业输出?

c# - 数据绑定(bind)后如何将图像设置为数据 GridView 单元格?

java - 每个单元的自定义单元工厂 JavaFX

iphone - 看不到 iAd 框架

ios - Trigger.io 中的内联视频播放

ios - 在 Swift 中子类化 PFObject

iphone - NavigationBar setShadowImage 并不总是有效

ios - Swift iOS 为 UIImage 添加不可见边框

ios - UITableView - UITableViewCell.Style .subtitle - 如何使 UIImageView 圆形? - swift 5