the button works only once

mrs.bassim

I have a page which contains two text fields, 2 labels and a button. When the button is clicked I am just checking if the fields are not empty and validate them. This works fine. But I can click the button only once. After that nothing will change and I'm not able to press the button or edit the text fields!

This is my code:

@IBAction func loginbtn(_ sender: Any) {
    showActivityIndicator(uiView: view)

    emailerrormsg.isHidden=true
    passworderrormsg.isHidden=true

    if emailtf.text == "" && passwordtf.text == "" {
        emailerrormsg.text = "Email is required!"
        emailerrormsg.isHidden = false
        passworderrormsg.text = "Password is required!"
        passworderrormsg.isHidden = false
        stopActivityIndicator()
    }
    else if emailtf.text == ""{
        emailerrormsg.text = "Email is required!"
        emailerrormsg.isHidden = false
        stopActivityIndicator()

    }
    else if !(isValidEmail(testStr: emailtf.text!)){
        emailerrormsg.text = "Please enter a valid email!"
        emailerrormsg.isHidden = false
        stopActivityIndicator()
    }else if passwordtf.text == "" {
        passworderrormsg.text = "Password is required!"
        passworderrormsg.isHidden = false
        stopActivityIndicator()
    }

    else{
        hashedpass = (passwordtf.text!).sha1()
        self.login(email: emailtf.text!, password: hashedpass)
    }
}

What am I doing wrong?

    func stopActivityIndicator(){
    DispatchQueue.main.async {
        self.loadingView.isHidden = true
    }
}
func showActivityIndicator(uiView: UIView) {
    let container: UIView = UIView()
    container.frame = uiView.frame
    container.center = uiView.center

    loadingView.frame = CGRect(x: 0,y:  0,width: 80,height: 80)
    loadingView.center = uiView.center
    loadingView.backgroundColor = UIColor(red:0.16, green:0.27, blue:0.60, alpha:1.0)
    loadingView.clipsToBounds = true
    loadingView.layer.cornerRadius = 10

    let actInd: UIActivityIndicatorView = UIActivityIndicatorView()
    actInd.frame = CGRect(x: 0.0,y: 0.0,width: 40.0,height: 40.0);
    actInd.activityIndicatorViewStyle =
        UIActivityIndicatorViewStyle.whiteLarge
    actInd.center = CGPoint(x: loadingView.frame.size.width / 2,y: loadingView.frame.size.height / 2);
    loadingView.addSubview(actInd)
    container.addSubview(loadingView)
    uiView.addSubview(container)
    actInd.startAnimating()
}
Puneet Sharma

You are hiding loading view in the stop method. Instead, hide container view. For this, you would need to make container view a class level object(just as you have made loading view)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related