oc如何判断imageview的图片是否为空

imageview图片是通过url设置,已有的字段是url的strring形式,现在要做一个判断,判断imageview的图片是不是存在,存在的话显示imageview,不存在就不显示imageview.
下面是我获取图片的代码:
[self.image sd_setImageWithURL:[NSURL URLWithString:articleData.cover]];
请问我该如何写判断

阅读 7.9k
1 个回答
if (!imageView.image) {
    // 图片不存在时, 请求网络加载图片
    [self.image sd_setImageWithURL:[NSURL URLWithString:articleData.cover] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        if (error) {
            // 图片加载失败
        } else {
            // 图片加载成功
        }
    }]
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题