Monday, October 22, 2012

iPhone AlertView



AlertVIew in iphone with 2 buttons OK/YES/DELETE and NO/CANCEL .
// 2 Buttons
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Wait" message:@"Are you sure you want to delete this.  This action cannot be undone" delegate:self cancelButtonTitle:@"Delete" otherButtonTitles:@"Cancel", nil];
[alert show];

Performing Action on Both Buttons i.e Delete and Cancel.
buttonIndex 0 for Delete
buttonIndex 1 for Cancel

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { 
   if (buttonIndex == 0) { 
        NSLog(@"Delete Tapped."); 
    } 
    else if (buttonIndex == 1) { 
       NSLog(@"Cancel Tapped!"); 
    } 
}

Same u can perform action with single button alert view.

AlertVIew in iphone with 1 buttons OK/YES
// 1 Button
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Wait" message:@"No INTERNET CONNECTION" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];

No comments:

Post a Comment