UiImageView + AFNetworking setImageWithURLRequest



  • I've got a menu on the side chart in it in the Headers, it's loaded from the feeding server by:

    __weak UIImageView *weakImageView = headerCell.imageViewPhoto;
    

    NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://11.111.111.1/%@",[[LZSettingsManager instance] objForKey:kUserPhotoUrl]]]
    cachePolicy:NSURLRequestReloadIgnoringCacheData
    timeoutInterval:60];

    [headerCell.imageViewPhoto setImageWithURLRequest:imageRequest placeholderImage:[UIImage imageNamed:@"menuEmptyUserPhoto"] success:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, UIImage * _Nonnull image) {

    weakImageView.alpha = 0.0;
    weakImageView.image = image;
    

    // [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadTableMenu" object:nil];
    [UIView animateWithDuration:0.25
    animations:^{
    weakImageView.alpha = 1.0;
    }];

    } failure:NULL];

    It's going to be a great start. Next, I'm in the profile changing the picture and everything on the server is changing, but the reference remains the same. (e.g. www.image1.png and starts www.image1.png) so after the change of pictures, I'm updating the table by the method.

    [self.tableView reloadData];

    But the picture's still the same, it's not changing, it's already been tried and done with the kesh. self.imageViewPhoto.image = nil; Still doesn't change, you get out of the application and you go back in, all the pictures are new.
    How do you get a new one on the same line?



  • Cash in AFNetworking is not disconnected. To avoid changing the main library, do the category. For example

    UIImageView (clearCache)

    with the following methods:

    - (void)clearImageCacheForURL:(NSURL *)url {
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
        [request addValue:@"image/*" forHTTPHeaderField:@"Accept"];
    
    UIImage *cachedImage = [[[self class] sharedImageCache] cachedImageForRequest:request];
    if (cachedImage) {
        [self clearCached:[[self class] sharedImageCache] Request:request];
    }
    

    }

    • (void)clearCached:(NSCache *)imageCache Request:(NSURLRequest *)request {
      if (request) {
      [imageCache removeObjectForKey:[[request URL] absoluteString]];
      }
      }

    Challenge clearImageCacheForURL You can clean up your previous picture in the kash.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2