(Tutorial Ios) Alert Obrolan Using Uialertcontroller


Alert Dialog merupakan komponen view yang berfungsi sebagai alert atau tampilan pemberitahuan terhadap user yang penting di dalam sebuah UI interface. Sejak iOS 8, mulai diperkenalkan UIAlertController sebagai pengganti UIAlertView (deprecated). UIAlertController mempunyai dua style.

Berikut rujukan menampilkan UIAlertController.

1. Simple Alert Dialog
Buat UIAlertController sederhana dengan style UIAlertControllerStyleAlert.
UIAlertController* alertDialog = [UIAlertController                                   alertControllerWithTitle:@"Ini Judul Ya?"                                   message:@"Hai Semuanya !"                                   preferredStyle:UIAlertControllerStyleAlert];      [self presentViewController:alertDialog animated:YES completion:nil]; 


2. Alert Dialog with Actions
Sama menyerupai Simple Alert Dialog, cuma disini kita menambahkan obrolan OK/Cancel.
UIAlertController* alertDialog = [UIAlertController                                   alertControllerWithTitle:@"Ini Judul Ya?"                                   message:@"Apakah Anda ingin melanjutkan ?"                                   preferredStyle:UIAlertControllerStyleAlert];          UIAlertAction* ok = [UIAlertAction                          actionWithTitle:@"Ya"                          style:UIAlertActionStyleDefault                          handler:^(UIAlertAction * action)                          {                              [alertDialog dismissViewControllerAnimated:YES completion:nil];                                                        }];     UIAlertAction* cancel = [UIAlertAction                              actionWithTitle:@"Batal"                              style:UIAlertActionStyleDefault                              handler:^(UIAlertAction * action)                              {                                  [alertDialog dismissViewControllerAnimated:YES completion:nil];                                                                }];          [alertDialog addAction:ok];     [alertDialog addAction:cancel];          [self presentViewController:alertDialog animated:YES completion:nil]; 


3. Action Sheet
Sama menyerupai Alert Dialog yang kedua, cuma kita mengganti style nya menjadi UIAlertControllerStyleActionSheet.
UIAlertController* alertDialog = [UIAlertController                                  alertControllerWithTitle:@"Ini Judul Ya?"                                  message:@"Pilih salah satu member JKT48 untuk jadi pacar kamu"                                  preferredStyle:UIAlertControllerStyleActionSheet];          UIAlertAction* pil1 = [UIAlertAction                          actionWithTitle:@"Melody JK48"                          style:UIAlertActionStyleDefault                          handler:^(UIAlertAction * action)                          {                              [alertDialog dismissViewControllerAnimated:YES completion:nil];                                                        }];     UIAlertAction* pil2 = [UIAlertAction                              actionWithTitle:@"Nabilah JKT48"                              style:UIAlertActionStyleDefault                              handler:^(UIAlertAction * action)                              {                                  [alertDialog dismissViewControllerAnimated:YES completion:nil];                                                                }];          UIAlertAction* pil3 = [UIAlertAction                            actionWithTitle:@"Veranda JKT48"                            style:UIAlertActionStyleDefault                            handler:^(UIAlertAction * action)                            {                                [alertDialog dismissViewControllerAnimated:YES completion:nil];                                                            }];           [alertDialog addAction:pil1];     [alertDialog addAction:pil2];     [alertDialog addAction:pil3];          [self presentViewController:alertDialog animated:YES completion:nil]; 

4. Alert Dialog with Textfield
Yang terakhir ini kita sanggup menambahkan textfield di Alert Dialog.
UIAlertController* alertDialog = [UIAlertController                                   alertControllerWithTitle:@"Ini Judul Ya?"                                   message:@"Masukkan username dan password :"                                   preferredStyle:UIAlertControllerStyleAlert];          UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault                                                handler:^(UIAlertAction * action) {                                                    //Do Some action here                                                                                                    }];     UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Batal" style:UIAlertActionStyleDefault                                                    handler:^(UIAlertAction * action) {                                                        [alertDialog dismissViewControllerAnimated:YES completion:nil];                                                    }];          [alertDialog addAction:ok];     [alertDialog addAction:cancel];          [alertDialog addTextFieldWithConfigurationHandler:^(UITextField *textField) {         textField.placeholder = @"Username";     }];     [alertDialog addTextFieldWithConfigurationHandler:^(UITextField *textField) {         textField.placeholder = @"Password";         textField.secureTextEntry = YES;     }];          [self presentViewController:alertDialog animated:YES completion:nil]; 


Tampilan dari masing-masing rujukan Alert Dialog alhasil sebagai berikut :


1. Simple Alert Dialog


2. Alert Dialog with Actions


3. Action Sheet


*TS gagal pensiun

4. Alert Dialog with Textfield



Source code lengkap sanggup di liat di https://github.com/andronut/iOSAlertDialog

Sekian dan agar bermanfaat
Happy Coding :)

Comments

Popular posts from this blog

Pewarnaan Objek Geometri Di Java 2D

(Tutorial Ios) Custom Uitableviewcell In Uitableview

(Tutorial Ios) Pull To Refresh With Uirefreshcontrol