如何上传用户个人资料图片

编程入门 行业动态 更新时间:2024-10-20 16:39:05
本文介绍了如何上传用户个人资料图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将个人资料图片上传到用户个人资料,但个人资料图片未显示在个人资料页面上,没有弹出错误,那么如何重组此代码以解决此问题?

I am trying to upload a profile image to the user profile but the profile image doesn't appear on the profile page there are no errors popping up so how do I restructure this code to fix this issue?

if let ProfileImageUrl = dictionary?["photo"] as? String { let url = URL(string: ProfileImageUrl) URLSession.shared.dataTask(with: url!, completionHandler: { ( data, response, Error ) in if Error != nil { print(Error!) return } DispatchQueue.main.async { self.ProfileImage.image = UIImage(data: data!) }

推荐答案

结尾闭包中的错误"应为错误".这只是命名约定的问题,不一定会导致代码失败.

The "Error" in trailing closure should be "error". It's just a matter of naming convention, doesn't necessarily cause the code to fail.

发现问题,您在数据任务上缺少".resume()".以下代码有效:

Found the problem, you're missing ".resume()" on the data task. The following code works :

if let imageUrl = urlString{ let url = URL(string: imageUrl) URLSession.shared.dataTask(with: url!) { (data, response, error) in if let error = error{ print("Error : \(error)") return } DispatchQueue.main.async { self.image.image = UIImage(data: data!) } }.resume() }

更多推荐

如何上传用户个人资料图片

本文发布于:2023-10-11 23:10:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483102.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:个人资料   上传   用户   图片

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!