When a UIButton is triggered, a UIActivityIndicator is started, and then stopped when implementLogin finishes:
-(IBAction)loginButton {
NSLog(@"loginButton triggered");
// Checks the Fields are not empty
if ([sessionIdField.text length] != 0 && [usernameField.text length] != 0 ) {
NSLog(@"Beginning Spinner");
// Displays spinner
[activitySpinner startAnimating];
[self implementLogin];
// Displays spinner
[activitySpinner stopAnimating];
}
}
However at runtime, the spinner doesn’t appear! I have set the spinner to ‘hide when stopped’.
When I set the activity indicator to animate before the view loads, it appears as it should, so I’m guessing it has a problem with the UIButton… (Also, I’m using ‘Touch Up Inside’ for the button.)
It’s a simple problem… Can anyone help?
Thanks
Whatever
implementLoginis doing (making a network request, perhaps?), it’s doing it on the main thread, which is likely blocking UI updates like spinner animation.You could recode something like this:
[Code is untested, but you get the idea.]
What is happening here is that you are dispatching the login task to the background, and the last thing that block will do is stop the spinner on the main thread (as a separate task).