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
Change
to
same for the first
if
alsoMy issue with Xcode 13 was posted
here
Select the style of default on the button.