Skip to content

Instantly share code, notes, and snippets.

@jkongie
Created March 16, 2010 00:50
Show Gist options
  • Save jkongie/333513 to your computer and use it in GitHub Desktop.
Save jkongie/333513 to your computer and use it in GitHub Desktop.
Add a spinner to a button in Objective C iPhone Development
//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