【问题标题】:Not able to update profile pic in MFSideMenu无法更新 MFSideMenu 中的个人资料图片
【发布时间】:2018-01-15 10:35:24
【问题描述】:

我正在尝试在侧边菜单 (MFSideMenu) 上更新我的个人资料图片,一旦我通过网络服务器更新个人资料图片,我想在我的 iOS 应用程序上进行设置。图片的网址相同,我无法升级它。我想问题是每次我更改图像时,都会从缓存中加载相同的图像 url,所以它不会改变。有没有什么方法可以在不需要更改 imageUrl 的情况下下载更改后的图像?

我总是得到回应

imageUrl :"user_image" = "profile/local/images/user_id/myimage"; 

因此,当我打开侧边菜单时,我会更新我的模型并从模型中获取信息。

`func menuAction(){ 
        self.getUserDetails()        
 }

func getUserDetails()  {
NotificationCenter.default.post(name: Notification.Name("NotificationIdentifier"), object: self)
self.menuContainerViewController.toggleLeftSideMenuCompletion(nil)
}`

【问题讨论】:

  • 使用 NSNotificationCentre
  • 我已经使用了 NSNotification center 但它仍然没有改变图像
  • 图片在网络服务器上更新了吗?
  • 是的,图像已在网络服务器上更新,但即使在触发通知后也不会在侧边菜单上更新。
  • 请分享通知功能的代码。

标签: ios swift afnetworking sdwebimage image-caching


【解决方案1】:

这可能是一个快速修复。但这不是最好的方法。

在设置(下载)图像时,向 url 添加不同的查询参数。

例如: 如果您的图片网址是http://www.yourserver.com/images/my_image.png,则将其更改为http://www.yourserver.com/images/my_image.png?any_name=timestamp

【讨论】:

  • 我已尝试添加 time_stamp 但仍无法更新图像。 'NSString *currentTimeStamp = [NSString stringWithFormat:@"%f",[[NSDate date] timeIntervalSince1970]]; NSString *user_profilePic = [NSString stringWithFormat:@"%@?time=%@",[json valueForKeyPath:@"userDetails.user_image"],currentTimeStamp];'
  • 我通过从应用程序委托触发通知并更新侧边菜单来解决此问题,以便每当应用程序打开时,数据都会被刷新。
猜你喜欢
  • 2021-12-15
  • 2017-09-12
  • 1970-01-01
  • 2020-04-26
  • 1970-01-01
  • 1970-01-01
  • 2013-04-13
  • 1970-01-01
  • 2022-11-16
相关资源
最近更新 更多