Pages

Friday 12 December 2014

How to show alert box in iOS and their delegates.



1] add the following code (where you want to show )

 UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
    @"Title" message:@"This is  alert" delegate:self 
    cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
    [alertView show];


2] and add UIAlertViewDelegate delegates in same file (.h) file , and add following code in (.m) file 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:
  (NSInteger)buttonIndex{
    switch (buttonIndex) {
        case 0:
            NSLog(@"Cancel clicked");
            break;
        case 1:
            NSLog(@"OK clicked");
            break;
        
        default:
            break;
    }
}





No comments:

Post a Comment