반응형
출처 카페 > 맥부기 애플(Apple OS.. | 블로
원문 http://cafe.naver.com/mcbugi/326609

안녕하세요 

iOS9에서 UIAlertView 사용하면 경고창이 떠서 UIAlertController 대한 간단한 코드입니다.


필요하신분들 있으실거 같아서 공유해드릴께요.


1,2,3번은 UIAlertControllerStyleAlert 샘플이고4번은UIAlertControllerStylerActionSheet입니다1,2번의 타입에 preferredStyle바꿔주시면 완성됩니다.




1. 기본 AlertView





UIAlertController *alertController = [UIAlertController

                                      alertControllerWithTitle:@"simpleAlert"

                                      message:@"UIAlertControllerStyleAlert"

                                     preferredStyle:UIAlertControllerStyleAlert];



[self presentViewController:alertController animated:YEScompletion:nil];






2. 버튼이 있는 AlertView





UIAlertController *alertController = [UIAlertController

                                      alertControllerWithTitle:@"simpleAlert"

                                      message:@"UIAlertControllerStyleAlert"

                                      preferredStyle:UIAlertControllerStyleAlert];



UIAlertAction *cancelAction = [UIAlertAction

                               actionWithTitle:@"Cancel"

                               style:UIAlertActionStyleCancel

                               handler:^(UIAlertAction *action)

                               {

                                   NSLog(@"Cancel action");

                               }];


UIAlertAction *okAction = [UIAlertAction

                           actionWithTitle:@"OK"

                           style:UIAlertActionStyleDefault

                           handler:^(UIAlertAction *action)

                           {

                               NSLog(@"OK action");

                          }];


UIAlertAction *resetAction = [UIAlertAction

                              actionWithTitle:@"Reset"

                              style:UIAlertActionStyleDestructive

                              handler:^(UIAlertAction *action)

                              {

                                  NSLog(@"Reset action");

                              }];

[alertController addAction:resetAction];

[alertController addAction:cancelAction];

[alertController addAction:okAction];


[self presentViewController:alertController animated:YEScompletion:nil];








3. TextInputAlert




-(IBAction)textFieldAlert:(id)sender{

    

    UIAlertController *alertController = [UIAlertController

                                          alertControllerWithTitle:@"TextInputAlert"

                                          message:@"Plane and secure text input"

                                          preferredStyle:UIAlertControllerStyleAlert];

    

    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField)

     {

         [textField addTarget:self

                       action:@selector(alertTextFieldDidChange:)

             forControlEvents:UIControlEventEditingChanged];

         textField.placeholder = @"LoginPlaceholder";

     }];

    

   [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField)

     {

         textField.placeholder =@"PasswordPlaceholder";

         textField.secureTextEntry = YES;

     }];

    

    UIAlertAction *okAction = [UIAlertAction

                               actionWithTitle:@"OK"

                               style:UIAlertActionStyleDefault

                               handler:^(UIAlertAction *action)

                               {

                                   UITextField *login = alertController.textFields.firstObject;

                                   UITextField *password = alertController.textFields.lastObject;

                                   NSLog(@"login = %@", login.text);

                                   NSLog(@"password = %@", password.text);

                               }];

    

    okAction.enabled = NO;

    [alertController addAction:okAction];

    [self presentViewController:alertController animated:YEScompletion:nil];

}


- (void)alertTextFieldDidChange:(UITextField *)sender

{

    UIAlertController *alertController = (UIAlertController *)self.presentedViewController;

    if (alertController)

    {

        UITextField *login = alertController.textFields.firstObject;

        UIAlertAction *okAction = alertController.actions.lastObject;

        okAction.enabled = login.text.length > 2;

    }

}


참고로 TextField 들어가게 되면 UIAlertControllerStyleActionSheet 타입을 이용할수 없습니다만약 이용하게 되면 아래와 같은 에러가 납니다.


*** Assertion failure in -[UIAlertController addTextFieldWithConfigurationHandler:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.30.14/UIAlertController.m:434

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Text fields can only be added to an alert controller of style UIAlertControllerStyleAlert'








4. ActionSheet









UIAlertController *alertController = [UIAlertController

                                      alertControllerWithTitle:@"simpleAlert"

                                      message:@"UIAlertControllerStyleAlert"

                                      preferredStyle:UIAlertControllerStyleActionSheet];



UIAlertAction *cancelAction = [UIAlertAction

                               actionWithTitle:@"Cancel"

                               style:UIAlertActionStyleCancel

                               handler:^(UIAlertAction *action)

                               {

                                   NSLog(@"Cancel action");

                               }];


UIAlertAction *okAction = [UIAlertAction

                           actionWithTitle:@"OK"

                           style:UIAlertActionStyleDefault

                           handler:^(UIAlertAction *action)

                           {

                               NSLog(@"OK action");

                           }];


UIAlertAction *resetAction = [UIAlertAction

                              actionWithTitle:@"Reset"

                              style:UIAlertActionStyleDestructive

                              handler:^(UIAlertAction *action)

                              {

                                  NSLog(@"Reset action");

                              }];

[alertController addAction:resetAction];

[alertController addAction:cancelAction];

[alertController addAction:okAction];


[self presentViewController:alertController animated:YEScompletion:nil];


반응형
블로그 이미지

앱스페이스

,
반응형
출처 카페 > 맥부기 애플(Apple OS.. | HappyTree
원문 http://cafe.naver.com/mcbugi/328099
앱을 올리려고하니 갑자기 인증서 문제가 생겨서 찾아보니

어제(2월14일)부로 애플의

Worldwide Developer Relations Certificate Authority 인증서가 만료됐다고 하더군요 (근데 왜 안알려줘ㅂㄷㅂㄷ)

키체인에 가보면 모든 개발용 인증서가

이 인증서는 유효하지 않은 발급자를 가지고 있음

라고 되어있을겁니다

1. 키체인 - 보기 - 만료된 인증서 보기 (여기에서 헤맸습니다;)

2. 2월 14일부로 만료가 된 Worldwide Developer Relations Certificate Authority 인증서를 삭제해줍니다.

3. Worldwide Developer Relations Certificate Authority를 새로 다운로드 받고 키체인에 넣습니다

4. 재붓


하아... '만료된 인증서 보기'를 몰라서 괜히 멀쩡한 인증서 다 지우고 다시 발급받았네ㅠㅠ

다른분들은 삽질하지 마시길;

오늘은 전세계 iOS&Mac 개발자들이 멘붕온날=_=

----------------------------------------

'아이뻐요'님의 추가제보
로그인항목에서 만료된 인증서가 안보인다면 시스템항목 들어가서 찾아보세요


반응형
블로그 이미지

앱스페이스

,
반응형

- (void) setData:(NSString *)name selector:(NSString*)name

{
 UIBarButtonItem *addNotiBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(NSSelectorFromString(name))];

}



반응형

'iOS > objective-c' 카테고리의 다른 글

[공유] iOS9 Contacts.framework 연락처 불러오기(상세)  (0) 2018.12.12
[공유] UIAlertController 간단한 코드입니다  (0) 2018.12.12
반각->전각  (0) 2018.12.12
ios7 status bar hidden  (0) 2018.12.12
nsstring, nsdata 변환  (0) 2018.12.12
블로그 이미지

앱스페이스

,