skip to Main Content

So I have the following code which executes upon tapping one side or another of my segmented control:

@IBAction func logInOrSignUpIndexChanged(_ sender: UISegmentedControl) {
    
    // Correct setup for Sign Up
    if sender.selectedSegmentIndex == 0 {
        
        confirmPasswordTextfield.isHidden = false
        confirmPasswordTextfield.isUserInteractionEnabled = true
        createAccountOrLogInButton.titleLabel?.text = "Create Account"
        rememberMeViewTopConstraint.constant = 20
        
    } // Correct setup for Log In
    else if sender.selectedSegmentIndex == 1 {
        
        confirmPasswordTextfield.isHidden = true
        confirmPasswordTextfield.isUserInteractionEnabled = false
        createAccountOrLogInButton.titleLabel?.text = "Log In"
        rememberMeViewTopConstraint.constant = -34
        
    }
    
}

For some reason, when I press the segmented index value of 1 (so the bottom if statement executes), the button title changes to "Log In" for a split second then reverts back to "Create Account". I tried changing the initial title of the button which of course doesn’t work, and tried taking out the line in the first if statement, that changes the title to "Create Account", and the title still changes, so I know that the first if statement is not being executed again for some arbitrary reason. Any idea what’s wrong?

2

Answers


  1. Change

    createAccountOrLogInButton.titleLabel?.text = "Log In"
    

    to

    createAccountOrLogInButton.setTitle("Log In",for:.normal)
    

    same for the first if also

    Login or Signup to reply.
  2. My issue with Xcode 13 was posted
    here

    Select the style of default on the button.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search