I have a side menu (table) in it, the picture in Headers is located, it is loaded from the server by the link method:

__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]; 

When you first start everything is super loaded. Next, I climb into the profile to change the picture and everything is fine on the server, it changes, but the link remains the same. (for example, www.image1.png and became www.image1.png) and so after changing the picture, I update the table with the method

 [self.tableView reloadData]; 

But the picture remains the same! it does not change, already with the cache I tried and did self.imageViewPhoto.image = nil; it still does not change, exit the application and enter again, the whole picture is new. How to make a new one immediately load on the same link?

    2 answers 2

    The cache in AFNetworking is not disabled. In order not to change the main library, make 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]]; } } 

    clearImageCacheForURL you can clear the previous image in the cache.

      Could solve only by UIImageView+AFNetworking.m out the code in the file UIImageView+AFNetworking.m

       // //Use the image from the image cache if it exists // UIImage *cachedImage = [imageCache imageforRequest:urlRequest withAdditionalIdentifier:nil]; // if (cachedImage) { // if (success) { // success(urlRequest, nil, cachedImage); // } else { // self.image = cachedImage; // } // [self clearActiveDownloadInformation]; // } else {