使用SWIFT的ResetPassword-iOS项目中警报中的可选文本

Optional Text in Alert in ResetPassword - iOS Project using Swift(使用SWIFT的ResetPassword-iOS项目中警报中的可选文本)
本文介绍了使用SWIFT的ResetPassword-iOS项目中警报中的可选文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的iOS应用程序的ResetPassword按钮,使用Xcode和SWIFT:

//ResetPssword Button
@IBAction func ResetPassword(sender: AnyObject) {

    if validateEmail(EmailTextField.text!) ==  false {
        print("Enter a Valid Email Address")
        let VaildMessage = "Enter an Email Address"
        //Empty TextField Alert Message
        self.disaplayErrorMessage(VaildMessage)
   }

    //Reset
    else {

        ref.resetPasswordForUser(EmailTextField.text) { (ErrorType) -> Void in
            if ErrorType != nil {

                let error = ErrorType
                print("There was an error processing the request (error.description)")
                let errorMessage:String = "The Email You Entered is not Exist"
                //Error Alert Message
                self.disaplayErrorMessage(errorMessage)

            } else {

                print("Password Reset Sent Successfully")
                let successMessage = "Email Message was Sent to You at (self.EmailTextField.text)"

                //Success Alert Message
                self.disaplayErrorMessage(successMessage)
            }

    } //reset

    } //Big Else

 } //Button


//Display Alert Message With Confirmation
func disaplayErrorMessage(theMessage:String)
{
    //Display alert message with confirmation.
    let myAlert = UIAlertController(title: "Alert", message: theMessage, preferredStyle: UIAlertControllerStyle.Alert);

    let OkAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default) {
        action in
        self.dismissViewControllerAnimated(true, completion: nil);
    }
    myAlert.addAction(OkAction);
    self.presentViewController(myAlert, animated: true, completion: nil)
}


   //Validate Email Function
func validateEmail(candidate: String) -> Bool {
    let emailRegex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}"
    return NSPredicate(format: "SELF MATCHES %@", emailRegex).evaluateWithObject(candidate)
}

如果密码重置成功发送,则会出现一个打印电子邮件地址的警报。但它会打印带有可选单词的电子邮件!

如果没有可选单词,我如何打印它?

推荐答案

您必须取消可选文本字段的换行

例如if let

if let text = self.EmailTextField.text {
    let successMessage = "Email Message was Sent to You at (text)"
    //Success Alert Message
    self.disaplayErrorMessage(successMessage)
} 

这篇关于使用SWIFT的ResetPassword-iOS项目中警报中的可选文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
Dropbox Files.download does not start when number of files in folder is gt; 1000(当文件夹中的文件数为1000时,Dropbox Files.Download不会启动)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)