gpt4 book ai didi

ios - 该按钮只工作一次

转载 作者:行者123 更新时间:2023-11-28 07:48:59 25 4
gpt4 key购买 nike

我有一个包含两个文本字段、2 个标签和一个按钮的页面。单击按钮时,我只是检查字段是否为空并验证它们。这很好用。但我只能点击一次按钮。之后什么都不会改变,我无法按下按钮或编辑文本字段!

这是我的代码:

@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)
}
}

我做错了什么?

    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()
}

最佳答案

您在停止方法中隐藏加载 View 。相反,隐藏容器 View 。为此,您需要将容器 View 设为类级别对象(就像您制作加载 View 一样)

关于ios - 该按钮只工作一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50191126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com