IOS create UIAlertViewController programmatically

前端 未结 4 711
时光取名叫无心
时光取名叫无心 2020-12-29 04:54

I\'m working on a ViewController with code (no storyboard). I\'m trying to add and AlertController

I have declare propery in .m

@property (nonatomic,         


        
4条回答
  •  一生所求
    2020-12-29 05:25

    - (void)logoutButtonPressed
    {
         UIAlertController * alert = [UIAlertController
                                     alertControllerWithTitle:@"Logout"
                                     message:@"Are You Sure Want to Logout!"
                                     preferredStyle:UIAlertControllerStyleAlert];
    
        //Add Buttons
    
        UIAlertAction* yesButton = [UIAlertAction
                                    actionWithTitle:@"Yes"
                                    style:UIAlertActionStyleDefault
                                    handler:^(UIAlertAction * action) {
                                        //Handle your yes please button action here
                                        [self clearAllData];
                                    }];
    
        UIAlertAction* noButton = [UIAlertAction
                                   actionWithTitle:@"Cancel"
                                   style:UIAlertActionStyleDefault
                                   handler:^(UIAlertAction * action) {
                                       //Handle no, thanks button
                                   }];
    
        //Add your buttons to alert controller
    
        [alert addAction:yesButton];
        [alert addAction:noButton];
    
        [self presentViewController:alert animated:YES completion:nil];
    }
    

提交回复
热议问题