UIAlertView first deprecated IOS 9

后端 未结 10 1313
南笙
南笙 2020-11-28 02:29

I have tried several ways to use UIAlertController,instead of UIAlertView. I tried several ways but I cannot make the alert action work. Here is my code that works fine in I

10条回答
  •  清歌不尽
    2020-11-28 02:48

     UIAlertController * alert = [UIAlertController
                                     alertControllerWithTitle:@"Are you sure you want to logout?"
                                     message:@""
                                     preferredStyle:UIAlertControllerStyleAlert];
    
        UIAlertAction* yesButton = [UIAlertAction
                                    actionWithTitle:@"Logout"
                                    style:UIAlertActionStyleDestructive
                                    handler:^(UIAlertAction * action)
                                    {
    
                                    }];
    
        UIAlertAction* noButton = [UIAlertAction
                                   actionWithTitle:@"Cancel"
                                   style:UIAlertActionStyleDefault
                                   handler:^(UIAlertAction * action) {
                                       //Handle no, thanks button
                                   }];
    
        [alert addAction:noButton];
        [alert addAction:yesButton];
    
        [self presentViewController:alert animated:YES completion:nil];
    

提交回复
热议问题