티스토리 뷰

Apple/Classes

UIAlertController Code Examples

아침엔커피한잔 2017. 7. 23. 15:02

http://hayageek.com/uialertcontroller-example-ios/


    
//Create UIAlertController
+ (instancetype)actionWithTitle:(NSString *)title style:(UIAlertActionStyle)style 
                            handler:(void (^)(UIAlertAction *action))handler;
//Adding an action
- (void)addAction:(UIAlertAction *)action;
//Adding text filed to UIAlertController.This method is supported only for  UIAlertControllerStyleAlert
- (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *textField))configurationHandler;

UIAlertController * alert=   [UIAlertController
                                    alertControllerWithTitle:@"My Title"
                                    message:@"Enter User Credentials"
                                    preferredStyle:UIAlertControllerStyleAlert];     
[self presentViewController:alert animated:YES completion:nil];

UIAlertAction* ok = [UIAlertAction
                     actionWithTitle:@"OK"
                     style:UIAlertActionStyleDefault
                     handler:^(UIAlertAction * action)
                     {
                         //Do some thing here
                         [view dismissViewControllerAnimated:YES completion:nil];
                          
                     }];
[alert addAction:ok]; // add action to uialertcontroller

UIAlertController * alert=   [UIAlertController
                                 alertControllerWithTitle:@"Info"
                                 message:@"You are using UIAlertController"
                                 preferredStyle:UIAlertControllerStyleAlert];
    
   UIAlertAction* ok = [UIAlertAction
                        actionWithTitle:@"OK"
                        style:UIAlertActionStyleDefault
                        handler:^(UIAlertAction * action)
                        {
                            [alert dismissViewControllerAnimated:YES completion:nil];
                             
                        }];
   UIAlertAction* cancel = [UIAlertAction
                            actionWithTitle:@"Cancel"
                           style:UIAlertActionStyleDefault
                           handler:^(UIAlertAction * action)
                           {
                               [alert dismissViewControllerAnimated:YES completion:nil];
                                                       
                           }];
    
   [alert addAction:ok];
   [alert addAction:cancel];
    
   [self presentViewController:alert animated:YES completion:nil];


---------------------------
UIAlertController * alert=   [UIAlertController
                                 alertControllerWithTitle:@"Info"
                                 message:@"You are using UIAlertController"
                                 preferredStyle:UIAlertControllerStyleAlert];
    
   UIAlertAction* ok = [UIAlertAction
                        actionWithTitle:@"OK"
                        style:UIAlertActionStyleDefault
                        handler:^(UIAlertAction * action)
                        {
                            [alert dismissViewControllerAnimated:YES completion:nil];
                             
                        }];
   UIAlertAction* cancel = [UIAlertAction
                            actionWithTitle:@"Cancel"
                           style:UIAlertActionStyleDefault
                           handler:^(UIAlertAction * action)
                           {
                               [alert dismissViewControllerAnimated:YES completion:nil];
                                                       
                           }];
    
   [alert addAction:ok];
   [alert addAction:cancel];
    
   [self presentViewController:alert animated:YES completion:nil];
------------------------
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
    textField.placeholder = @"Password"; //for passwords
    textField.secureTextEntry = YES;
}];
-----------------------
UIAlertController * alert=   [UIAlertController
                                  alertControllerWithTitle:@"My Title"
                                  message:@"Enter User Credentials"
                                  preferredStyle:UIAlertControllerStyleAlert];
     
    UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
                                               handler:^(UIAlertAction * action) {
                                                   //Do Some action here
                                                    
                                               }];
    UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault
                                                   handler:^(UIAlertAction * action) {
                                                       [alert dismissViewControllerAnimated:YES completion:nil];
                                                   }];
     
    [alert addAction:ok];
    [alert addAction:cancel];
     
    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"Username";
    }];
    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"Password";
        textField.secureTextEntry = YES;
    }];
     
    [self presentViewController:alert animated:YES completion:nil];
/


'Apple > Classes' 카테고리의 다른 글

NSOperation Code Examples  (0) 2017.07.27
NSDate Code Examples  (0) 2017.07.23
NSURLSession Code Examples  (0) 2017.06.20
NSTimer Code Examples  (0) 2017.06.17
NSDictionary Code Examples  (0) 2017.06.12
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함