【发布时间】:2021-02-24 22:25:47
【问题描述】:
所以我有以下代码在点击我的分段控件的一侧或另一侧时执行:
@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
}
}
由于某种原因,当我按下分段索引值 1(所以底部的 if 语句执行)时,按钮标题会在一瞬间变为“登录”,然后恢复为“创建帐户”。我尝试更改当然不起作用的按钮的初始标题,并尝试删除第一个 if 语句中的行,将标题更改为“创建帐户”,并且标题仍然更改,所以我知道首先,如果出于某种任意原因没有再次执行 if 语句。知道有什么问题吗?
【问题讨论】:
标签: ios swift xcode uibutton title