我还是新编码。我已经设置了我的注册屏幕,但我想强制要求在注册期间上传个人资料图片。我试图添加和“如果声明”,以显示一个警报,如果照片没有上传,但我没有成功让它工作。有什么建议?这是我的代码:
class SignUpViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet var usernameField: UITextField!
@IBOutlet var activityIndicator: UIActivityIndicatorView!
@IBOutlet var message: UILabel!
@IBOutlet var emailField: UITextField!
@IBOutlet var passwordField: UITextField!
@IBOutlet var firstNameField: UITextField!
@IBOutlet var lastNameField: UITextField!
@IBOutlet var profilePic: UIImageView!
@IBAction func submitDataAction(sender: AnyObject) {
var userName = usernameField.text
var userEmail = emailField.text
var userPassword = passwordField.text
var firstName = firstNameField.text
var lastName = lastNameField.text
var initialImage = UIImage(named: "DidNotLoad")
var picfile = profilePic.image
let imageData = UIImagePNGRepresentation(picfile)
let imageFile = PFFile(data: imageData)
userEmail = userEmail.lowercaseString
// Start activity indicator
activityIndicator.hidden = false
activityIndicator.startAnimating()
var newUser = PFUser()
newUser.username = userName.lowercaseString
newUser.password = userPassword
newUser.email = userEmail
newUser["FirstName"] = firstName
newUser["LastName"] = lastName
newUser["ProfilePic"] = imageFile
newUser.signUpInBackgroundWithBlock {(succeeded: Bool, error: NSError?) -> Void in
if error == nil {
dispatch_async(dispatch_get_main_queue()) {
self.performSegueWithIdentifier("PushToEventsTableFromSignUp", sender: self)
}
self.activityIndicator.stopAnimating()
}
else {
if let message: AnyObject = error!.userInfo!["error"] {
self.message.text = "\(message)"
}
}
}
}
@IBAction func uploadPhoto(sender: AnyObject) {
//Create variable for image controller
var picPhoto = UIImagePickerController()
picPhoto.delegate = self
picPhoto.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
picPhoto.allowsEditing = true
self.presentViewController(picPhoto, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
self.dismissViewControllerAnimated(true, completion: { () -> Void in
})
profilePic.image = image
}
override func viewDidLoad() {
super.viewDidLoad()
self.makingRoundedImageProfileWithRoundedBorder()
activityIndicator.hidden = true
activityIndicator.hidesWhenStopped = true
// Do any additional setup after loading the view.
}
private func makingRoundedImageProfileWithRoundedBorder() {
self.profilePic.layer.cornerRadius = self.profilePic.bounds.size.width/2;
self.profilePic.layer.masksToBounds = true
// self.profilePic.clipsToBounds = true
//Create Border around profile Pic
self.profilePic.layer.borderWidth = 2.0
self.profilePic.layer.borderColor = UIColor.whiteColor().CGColor
}
答案 0 :(得分:0)
如果用户在开始真正的Parse-signup之前选择了图像,则可以检查。例如,在didFinishPickingImage
方法中,您可以将bool设置为true:
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
self.dismissViewControllerAnimated(true, completion: { () -> Void in
})
profilePic.image = image
pictureChosen = true
}
之后,如果布尔值为真,请检查submitDataAction
:
if pictureChosen{
//Submit the signup
}