UIAlertView deprecated in iOS 9

In this post i will tell you about UIAlertController in iOS. 

UIAlertController is used to show alerts in your application . For iOS 8 and below , UIAlertView is used to pop up alerts in the app .

But as now iOS 9 is launched , iOS 9 deprecated UIAlertView. So now we need to add UIAlertController for showing alerts .

I will show you to open alert on the button`s  click .

Firstly add button in your project by :

  UIButton *clickHere = [[UIButton alloc]initWithFrame:CGRectMake(60, 100, 100, 40)];
    [clickHere setTitle:@"Alert" forState:UIControlStateNormal];
    [clickHere setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [clickHere addTarget:self action:@selector(clickAction) forControlEvents:UIControlEventTouchUpInside];

// Here clickAction is the button Action which we need to implement .


    [self.view addSubview:clickHere];

Now , I am adding UIButton`s Action .


- (void)clickAction
{

     UIAlertController * alert=   [UIAlertController alertControllerWithTitle:@"No Internet Connection" message:@"You require an internet connection WiFi or cellular network." preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction* OKButton = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
     {
      [alert dismissViewControllerAnimated:YES completion:nil];
      }];
    
    [alert addAction:OKButton];
    [self presentViewController:alert animated:YES completion:nil];

}


This will add new UIAlertController to your project.


UIAlertController

Thank you :)


Comments

Popular Posts