我为另一个函数编写了几乎完全相同的代码并且它可以正常工作 - 但由于某种原因,这里没有工作。我只想在API从服务器检索数据时使用活动指示器添加此灰色视图,然后在服务器返回数据时隐藏它...错误标签已正确更新,但视图永远不会消失... (grayLoadingView - 此视图包含活动指示符)
@objc private func signUpButtonPressed() {
print("sign up pressed")
if validateTextFields() {
**//start activity indicator
grayLoadingView.isHidden = false**
createNewUser(username: usernameTextField.text!, email: emailTextField.text!, password: passwordTextField.text!, completionHandler: { (message) in
print("message-> \(message)")
**//hide activity indicator
self.grayLoadingView.isHidden = true**
if message == "Account created successfully" {
OperationQueue.main.addOperation {
self.dismiss(animated: false, completion: nil)
let nextScreen = HomeScreenViewController()
nextScreen.username = self.usernameTextField.text!
let newNavController = UINavigationController(rootViewController: nextScreen)
self.present(newNavController, animated: true, completion: nil)
}
} else {
DispatchQueue.main.async {
//display error message
self.errorLabel.isHidden = false
self.errorLabel.text = message
}
}
})
} else {
print("empty")
}
}