Я хочу показать индикатор активности после того, как пользователь введет учетные данные для входа и нажмет кнопку входа. Это казалось простым, но индикатор не отображается, когда я запускаю (сборка прошла успешно). Я не уверен, что это потому, что, когда приложение запускается по-настоящему, оно будет передавать учетные данные на сервер для проверки, но этот код еще не активен, поэтому вход в систему происходит мгновенно, или если я написал это неправильно, но не чтобы вызвать ошибку. Спасибо за помощь.
@IBAction func loginButtonTapped(sender: AnyObject) {
//add error checking for loginEntered and passwordEntered if they are blank
if loginEntered.text == "" || passwordEntered.text == "" {
//Define the variable error for the message that should be displayed
self.alertError = "Please enter your Login ID and/or Password"
}
if self.alertError != "" { //if there is an error with the login
//Display the error message on screen
self.displayAlert("Missing Required Information", error: alertError)
//reset error variable
self.alertError = ""
//return the user to the LoginID field and empty it if there is data in it. Empty the password field too. ?? How do I do that??
} else { //the login ID and password are entered
//setup for a spinner to notify the user the app is working on something
activityIndicator = UIActivityIndicatorView(frame: CGRectMake(0, 0, 80, 80))
activityIndicator.center = self.view.center;
activityIndicator.backgroundColor = (UIColor(white: 0.3, alpha: 0.5)) //creates a background behind the spinner
activityIndicator.layer.cornerRadius = 10
activityIndicator.hidesWhenStopped = true
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.WhiteLarge
view.addSubview(activityIndicator)
activityIndicator.startAnimating()
UIApplication.sharedApplication().beginIgnoringInteractionEvents()
Код переходит к нескольким операторам if, основанным на учетных данных для входа и возвращающих данные с сервера. Наконец, он перестает игнорировать события взаимодействия. Наконец, я поместил этот же код в IBAction для кнопки, которую создал для проверки кода. Работает на кнопку.