Reputation: 165
How to change this obj c code that suits with iOS 9
above ? i have this error when i updating X Code into 8.2.1 . The code as below
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"Continue"]){
NSLog(@"Continue...");
[self performSegueWithIdentifier:@"createlogin" sender:self];
}
}
The error:
UIAlertView is deprecated : first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead
Thanks.
Upvotes: 0
Views: 3635
Reputation: 224
try this:
UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"Your message title"
message:@"Enter your message here."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
{
NSLog(@"Ok Action");
}];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Skip" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
{
NSLog(@"Cancel Action");
}];
[controller addAction:okAction];
[controller addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
Upvotes: 0
Reputation: 135
Use this code
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction * continueButton = [UIAlertAction actionWithTitle:@"Continue" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
[self performSegueWithIdentifier:@"createlogin" sender:self];
}];
UIAlertAction * cancelButton = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
}];
[alert addAction:continueButton];
[alert addAction:cancelButton];
[self presentViewController:alert animated:YES completion:nil];
Upvotes: 0
Reputation: 663
UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"Add Title" message:@"Add Message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction * actionOK = [UIAlertAction actionWithTitle:@"Button Title" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//Here Add Your Action
}];
UIAlertAction * actionCANCEL = [UIAlertAction actionWithTitle:@"Second Button Title" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//Add Another Action
}];
[alert addAction:actionOK];
[alert addAction:actionCANCEL];
[self presentViewController:alert animated:YES completion:nil];
Use this Method if any need ask me and for more Information use this Link http://useyourloaf.com/blog/uialertcontroller-changes-in-ios-8/
Upvotes: 2