我从我的 FireBase 孩子(“用户”到我的 UITextFields 和 UITextViews 中检索快照时遇到了一些问题
检索它们后,我希望它们可以通过 DataService 中的代码进行编辑
谁能帮忙??????
enter code here
import UIKit
import Firebase
class ProfileTableViewController: UITableViewController, UINavigationControllerDelegate, UITextViewDelegate, UITextFieldDelegate {
@IBOutlet weak var profileImage: UIImageView!
@IBOutlet weak var username: UITextField!
@IBOutlet weak var email: UITextField!
var imagePicker = UIImagePickerController()
var selectPhoto: UIImageView!
@IBOutlet weak var schoolProfile: UITextField!
@IBOutlet weak var interestProfile: UITextView!
@IBOutlet weak var aboutProfile: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
self.title = "EDIT PROFILE"
profileImage.layer.cornerRadius = profileImage.frame.size.height / 2
profileImage.clipsToBounds = true
// Display data in tabletcells
if let user = DataService.dataService.currentUser {
username.text = user.displayName
email.text = user.email
// schoolProfile.text = user.School
// print(user.photoURL)
if user.photoURL != nil {
if let data = NSData(contentsOf: user.photoURL!) {
self.profileImage.image = UIImage.init(data: data as Data)
}
}
}else {
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo image: UIImage, editingInfo: [String: Any]?) {
profileImage.image = image
imagePicker.dismiss(animated: true, completion: nil)
}
}
// Change profileimage
@IBAction func selectPhoto(_ sender: UITapGestureRecognizer) {
resignFirstResponder()
imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.allowsEditing = true
if UIImagePickerController.isSourceTypeAvailable(.camera) {
imagePicker.sourceType = .camera
}else {
imagePicker.sourceType = .photoLibrary
}
self.present(imagePicker, animated: true, completion: nil)
}
@IBAction func saveDidTapped(_ sender: AnyObject) {
var data = NSData()
data = UIImageJPEGRepresentation(profileImage.image!, 0.1)! as NSData
DataService.dataService.SaveProfile(username: username.text!, email: email.text!, data: data)
}
}
extension ProfileTableViewController: UIImagePickerControllerDelegate {
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo image: UIImage, editingInfo: [String: Any]?) {
profileImage.image = image
imagePicker.dismiss(animated: true, completion: nil)
}
}