Skip to content

Instantly share code, notes, and snippets.

@rsaunders100
Created September 19, 2011 09:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsaunders100/1226218 to your computer and use it in GitHub Desktop.
Save rsaunders100/1226218 to your computer and use it in GitHub Desktop.
(iOS) UIAlert View Example - Has a delegate for Yes/No Taps Will only display popup once
- (void) showConfirmationAlert
{
// A quick and dirty popup, displayed only once
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"HasSeenPopup"])
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Question"
message:@"Do you like cats?"
delegate:self
cancelButtonTitle:@"No"
otherButtonTitles:@"Yes",nil];
[alert show];
[alert release];
[[NSUserDefaults standardUserDefaults] setValue:@"YES" forKey:@"HasSeenPopup"];
}
}
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
// 0 = Tapped yes
if (buttonIndex == 0)
{
// ....
}
}
@mrpossoms
Copy link

Yes is actually buttonIndex of 1

@StoneMoe
Copy link

StoneMoe commented May 6, 2016

Should replace this by UIAlertController now~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment