Created
March 16, 2010 00:50
-
-
Save jkongie/333513 to your computer and use it in GitHub Desktop.
Add a spinner to a button in Objective C iPhone Development
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//How to add a spinner onto a button | |
- (IBAction)deleteAction:(id)sender { | |
[self.navigationController.view addSubview:activityIndicator]; | |
[activityIndicator startAnimating]; | |
// Spinner won't start spinning until we finish processing this event, so | |
// we're just going to schedule the rest of what we need to do. | |
// doDelete: will run when the main thread gets its next event. | |
[self performSelectorOnMainThread:@selector(doDelete:) | |
withObject:record | |
waitUntilDone:NO]; | |
// removeSpinner: will run in at least one second, but will wait if | |
// another event (like the doDelete: one) is in the middle of running. | |
[self performSelector:@selector(removeSpinner:) | |
withObject:activityIndicator | |
afterDelay:1.0]; | |
} | |
- (void)doDelete:(id)record { | |
[record delete]; // or whatever it is you need to do | |
} | |
- (void)removeSpinner:(UIActivityIndicator*)activityIndicator { | |
[activityIndicator stopAnimating]; | |
[activityIndicator removeFromSuperview]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment