Same code is working perfectly in another view controller.Help me Out to get rid of this problem. Here Is the Code….
import UIKit
import Firebase
class SettingTableViewController: UITableViewController, UIImagePickerControllerDelegate & UINavigationControllerDelegate {
@IBOutlet weak var profileImgView: UIImageView!
@IBOutlet weak var usernameTexfield: UITextField!
@IBOutlet weak var emailTextfield: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "Edit Profile"
fetchCurrentUser()
}
func fetchCurrentUser() {
Api.User.observeCurrentUser { (user) in
self.usernameTexfield.text = user.username
self.emailTextfield.text = user.email
if let profileUrl = URL(string: user.profileImageUrl!) {
self.profileImgView.sd_setImage(with: profileUrl)
}
}
}
@IBAction func SaveButton_TouchUpInside(_ sender: Any) {
if let profileImg = self.profileImgView, let imageData = profileImg.jpegData(compressionQuality: 0.1) {
AuthService.updateUserInfo(username: usernameTexfield.text!, email: emailTextfield.text!, imageData: imageData, onSuccess: {
ProgressHUD.showSuccess("Success")
}, onError: { (errorMaessage) in
ProgressHUD.showError(errorMaessage)
})
}
}
@IBAction func LogOutButton_TouchUpinside(_ sender: Any) {
}
@IBAction func EditProfileBtn_TouchUpInside(_ sender: Any) {
let pickercontroller = UIImagePickerController()
pickercontroller.delegate = self
present(pickercontroller, animated: true, completion: nil)
}
}
extension SettingTableViewController {
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
print("did finish picking media")
if let image = info["UIImagePickerControllerOrignalImage"]
as? UIImage{
profileImgView.image = image
}
dismiss(animated: true, completion: nil)
}
}
4
Answers
This Really works.
@M.Ali @TaimoorArif After using Image property The Build Succeed, can you guys check the Edit profile button's code why the image is not uploading. I think there is something that I am missing.
Make sure to use the
image
property of theprofileImgView
not theprofileImgView
directly.So Replace this line
if let profileImg = self.profileImgView, let imageData = profileImg.jpegData(compressionQuality: 0.1) {
with this
if let profileImg = self.profileImgView.image, let imageData = profileImg.jpegData(compressionQuality: 0.1) {
You are only setting profileImgView to profileImg. You have to set profileImageView.image to get this work properly.
Try this code in Save button action:
Hope this works.
Take a variable, let:
Now in the delegate function of imagePickerController you have to do:
Now in SaveButton action do this:
Hope this works.