Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a simple UIAlertView

What is some starter code I could use to make a simple UIAlertView with one "OK" button on it?

like image 924
Linuxmint Avatar asked Dec 16 '10 17:12

Linuxmint


1 Answers

When you want the alert to show, do this:

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"ROFL"                                                      message:@"Dee dee doo doo."                                                      delegate:self                                                      cancelButtonTitle:@"OK"                                                      otherButtonTitles:nil]; [alert show];      // If you're not using ARC, you will need to release the alert view.     // [alert release]; 

If you want to do something when the button is clicked, implement this delegate method:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {     // the user clicked OK     if (buttonIndex == 0) {         // do something here...     } } 

And make sure your delegate conforms to UIAlertViewDelegate protocol:

@interface YourViewController : UIViewController <UIAlertViewDelegate>  
like image 137
sudo rm -rf Avatar answered Nov 10 '22 00:11

sudo rm -rf