我已经好几次看了这段代码,即使是现在一小时,但我发现错误。 :(
没有错误编译项目,根本没有显示错误,但是我无法选择图像,当我按下UIImage时,没有任何反复发生。
在" signUp View Controller"中使用类似的代码注册一切顺利时,您可以选择(选择)图像,并在Firebase上正确保存图像。
此外,在这个" ProfileTableViewController"中,一切都很好,Firebase上保存的图像被加载并显示在Profile View中,但是无法选择它(按下它)来选择它并进行更改。
其他所有内容都经过测试,更改和保存(用户名甚至是电子邮件),只有图片才能给我带来问题。你能看一下代码并告诉我我做错了吗?
感谢。
import UIKit
class ProfileTableViewController: UITableViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
@IBOutlet weak var profileImage: UIImageView!
@IBOutlet weak var username: UITextField!
@IBOutlet weak var email: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Edit Profile"
let tap = UITapGestureRecognizer(target: self, action: #selector(ProfileTableViewController.selectPhoto(_:)))
tap.numberOfTapsRequired = 1
profileImage.addGestureRecognizer(tap)
profileImage.layer.cornerRadius = profileImage.frame.size.height / 2
profileImage.clipsToBounds = true
if let user = DataService.dataService.currentUser {
username.text = user.displayName
email.text = user.email
if user.photoURL != nil {
if let data = NSData(contentsOfURL: user.photoURL!) {
self.profileImage!.image = UIImage.init(data: data)
}
}
} else {
// No user is signed in
}
}
func selectPhoto(tap: UITapGestureRecognizer) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.allowsEditing = true
if UIImagePickerController.isSourceTypeAvailable(.Camera) {
imagePicker.sourceType = .Camera
} else {
imagePicker.sourceType = .PhotoLibrary
}
self.presentViewController(imagePicker, animated: true, completion: nil)
}
// UIImagePicker Delegate
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
profileImage.image = image
dismissViewControllerAnimated(true, completion: nil)
}