【问题标题】:PINRemoteImage delete cachePINRemoteImage 删除缓存
【发布时间】:2016-01-23 14:24:41
【问题描述】:

我在我的 iOS 应用程序中使用 PINRemoteImage 在 UIImageView 上设置图像。我总是有相同的图像链接,但同时图像可以改变(我可以上传不同的图像),但每当我在 UIImageView 上调用 pin_setImageFromURL 时,它总是设置一个旧图像(如果我删除应用程序并重新安装它,则不会)。我发现调用 [[[PINRemoteImageManager sharedImageManager] defaultImageCache] removeAllObjects] 会从缓存中删除图像,但只有当我关闭并重新打开应用程序时,有没有人知道如何在调用上部方法后强制应用程序立即更新缓存?

【问题讨论】:

    标签: ios objective-c caching uiimageview


    【解决方案1】:

    我发现了这种清除缓存的方法:

    [[[PINRemoteImageManager sharedImageManager] cache] removeObjectForKey:
        [[PINRemoteImageManager sharedImageManager]cacheKeyForURL:your_URL processorKey:nil]];
    

    因此,在您的- (void)viewWillAppear:(BOOL)animated 中,您可以使用 your_URL 再次设置您的 ImageView。

    这在我身边成功了;)

    【讨论】:

    • 这似乎是使用 Texture + ASNetworkImageNode 时清除 PINCache 的方法。
    【解决方案2】:

    在 Swift 中从缓存中删除图像的一个简单解决方案是:

    import PINRemoteImage
    import PINCache
    
    if let cacheKey = PINRemoteImageManager.sharedImageManager().cacheKeyForURL(NSURL(string: "http://your-image-url"), processorKey: nil) {
        PINRemoteImageManager.sharedImageManager().cache.removeObjectForKey(cacheKey, block: nil)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-01
      • 2012-10-16
      • 1970-01-01
      • 2017-05-28
      • 2011-05-12
      • 2012-03-19
      • 2014-10-20
      • 2023-03-10
      相关资源
      最近更新 更多