【问题标题】:drawRect and AFNetworkingdrawRect 和 AFNetworking
【发布时间】:2013-03-03 17:33:24
【问题描述】:

我正在使用以下代码

      self.imageView = [[UIImageView alloc] init];
  [self.imageView setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"profile-image-placeholder"]];
    [self setNeedsLayout];
    [self setNeedsDisplay];

但在 drawRect 中只能看到使用以下占位符的图像

[self.imageView.image drawAtPoint:CGPointMake(15.0f, 5.0f)];

对此有什么想法吗?

【问题讨论】:

  • 您知道远程图像在下载后将可供您的 imageView 使用,而在使用其 URL 设置图像视图后不会立即使用?
  • 我正在成功地使用我的答案。

标签: ios afnetworking drawrect


【解决方案1】:

我认为你需要做的就是这个。如果单元被重复使用,AFNetworking 将取消图像操作,因此您无需担心这种边缘情况。

[self.imageView setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]] placeholderImage:[UIImage imageNamed:@"profile-image-placeholder"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
      self.imageview.image=image;
      [self setNeedsLayout];
      [self setNeedsDisplay];

    } failure:nil];

【讨论】:

    猜你喜欢
    • 2013-04-04
    • 1970-01-01
    • 2023-03-14
    • 2014-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多