2014-10-07 1 views
11

iOS 7에서는 완벽하게 표시되는 UIAlertView가 있지만 iOS 8에서는 버튼이나 레이블이 표시되지 않습니다. 알림은 여전히 ​​표시되지만 작은 흰색 상자입니다. 확인 및 취소 단추는 이벤트도 가져 오지만 텍스트는 표시되지 않습니다.iOS 8 : UIAlertView/UIAlertController가 텍스트 또는 버튼을 표시하지 않음

가 나는 아이폰 OS 8 프레임을 확인

- (IBAction)sel_btnLogout:(id)sender { 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Logout!" message:@"Are you sure you want to logout?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil]; 
    [alert show]; 
} 

버튼의 클릭에 표시 할이 경고를 사용하고 있습니다 : 그것은주고있다 (0,0,0,0)하지만 아이폰 OS 7이 제공하고 있습니다 명확한 가치.

또한 uialertview의 하위 뷰를 반복 검사했습니다. iOS7에서는 경보의 하위보기를 발견하면 루프가 진행됩니다. iOS8에서는 alertView의 하위보기가 없다고 말합니다.

+0

이것이 실제 코드입니까? 실제 코드를 게시하지 않은 경우 게시하십시오. – rmaddy

+0

@siddhant는 실제 코드를 게시합니다. 이 코드는 iOS 8에서도 작동합니다. 따라서 여기에 프로젝트에서 작성한 정확한 코드를 복사하십시오. – Jasmeet

+0

시도해보십시오. http://stackoverflow.com/questions/25927676/uialertview-title-not-display/25928050#25928050 –

답변

4

나는 내 문제에 대한 해답을 얻었다. 문제는 프로젝트에서 UIFont + 대체 카테고리를 사용하고 있다는 것이 었습니다. 이것은 iOS 7에서 잘 작동했지만 iOS 8에서는 사용되지 않는 메소드를 거의 사용하지 않았습니다. 이로 인해 왜 그런지 알 수 없지만 경고보기에는 레이블이 표시되지 않습니다.

해결 방법 : 프로젝트에서 범주를 삭제하고 xib를 통해 글꼴을 설정하십시오. 프로젝트 작업 공간에 글꼴의 .tff 파일을 배치하면 사용자 정의 글꼴 아래 xib에 해당 글꼴 이름이 표시됩니다. UIFont + Replacement 범주를 사용할 필요가 없습니다.

+0

작동합니다 : D. 고마워, 싯닷 나는 미쳐 가고 있었다!! –

+1

@AlexGuerra - 오신 것을 환영합니다. 종류의 이상한 문제와 심지어 더 이상한 해결책 :) – Siddhant

-5

나는 이것이 UIAlertview 문제가 아니라고 생각합니다. 이 잘 작동을 확인하시기 바랍니다 .. 내가 코드 문제를 생각

...........

을 아래처럼 viewDidLoad에이 코드를 넣어 어떤 view controller에 :

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"My message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil]; 
    [alert show]; 
} 
+0

1) 'viewDidLoad'의 경고를 표시하지 마십시오. 보기가 아직 보이지 않습니다. 2)이 질문에 어떻게 대답합니까? OP는 iOS 7에서 코드가 작동하므로 경고가 표시되는 곳에서 문제가되지 않습니다. – rmaddy

+0

@rmaddy - 경고는 iOS8에 계속 표시되지만 텍스트 또는 버튼 라벨은 표시되지 않습니다. 나는 프레임을 점검했다 ... 그것은 (0,0,0,0) – Siddhant

+0

@Siddhant이 무관계 한 대답이 아니라 당신의 질문에 그 정보를 넣는다. – rmaddy

2

iOS 8에서는 UIAletrviewUIActionSheetUIAlertcontroller으로 바꿔야합니다.

[[[UIAlertView alloc] initWithTitle:@"AlertView in iOS 8." message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]show]; 

UIAlertView 자세한 내용은 아이폰 OS 8에서 지원되지 않습니다이

를 방문하십시오 당신은
Apple Alertcontroller 당신이 메시지 대신 제목을 설정할 수 있습니다 아이폰 OS 8을

12

먼저 사과 포럼에서이 문서를 읽어 http://nshipster.com/uialertcontroller/. 당신이 아이폰 OS 7, 아이폰 OS 8에 대해 별도의 코드를 작성하는 거라면 https://developer.apple.com/LIBRARY/IOS/documentation/UIKit/Reference/UIAlertViewDelegate_Protocol/index.html

그래서 대신 UIAlertController를 사용한다 :

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"AlertView in iOS 8" message:nil preferredStyle:UIAlertControllerStyleAlert]; 
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 
[self dismissViewControllerAnimated:YES completion:nil]; 
}]]; 
[self presentViewController:alertController animated:YES completion:nil]; 
+1

이것은 질문에 대답하려고 시도하지 않습니다. OP는 iOS 8에서'UIAlertView'로 여전히 완벽하게 제목과 메시지를 원합니다. – rmaddy

29

확인 클래스를 사용할 수있는 경우

if ([UIAlertController class]) 
{ 

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Alert title" message:@"Alert message" preferredStyle:UIAlertControllerStyleAlert]; 

    UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]; 
    [alertController addAction:ok]; 

    [self presentViewController:alertController animated:YES completion:nil]; 

} 
else 
{ 

    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"Alert title" message:@"Alert message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 

    [alert show]; 

} 
1

당신은 그 코드

if (([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedAscending)) 
{ 
    // use UIAlertView 
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:Title message:desc delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
    [alert show]; 
} 
else { 
    // use UIAlertController 
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:Title message:desc preferredStyle:UIAlertControllerStyleAlert]; 
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 

    }]; 
    [alert addAction:okAction]; 
    [self presentViewController:alert animated:YES completion:nil]; 
} 
3

아래의 경고에 필드와 버튼을 추가하는 방법을 이해하기 위해 코드를 읽어 보시기 바랍니다 확인할 수 있습니다.

- (IBAction)UIAlertControllerWithActionSheetTextFields:(id)sender { 
 
    UIAlertController * alert= [UIAlertController 
 
            alertControllerWithTitle:@"Info" 
 
            message:@"You are using UIAlertController with Actionsheet and text fields" 
 
            preferredStyle:UIAlertControllerStyleAlert]; 
 
    
 
    UIAlertAction* ok = [UIAlertAction 
 
         actionWithTitle:@"OK" 
 
         style:UIAlertActionStyleDefault 
 
         handler:^(UIAlertAction * action) 
 
         { 
 
          NSLog(@"Resolving UIAlert Action for tapping OK Button"); 
 
          [alert dismissViewControllerAnimated:YES completion:nil]; 
 
           
 
         }]; 
 
    UIAlertAction* cancel = [UIAlertAction 
 
          actionWithTitle:@"Cancel" 
 
          style:UIAlertActionStyleDefault 
 
          handler:^(UIAlertAction * action) 
 
          { 
 
           NSLog(@"Resolving UIAlertActionController for tapping cancel button"); 
 
           [alert dismissViewControllerAnimated:YES completion:nil]; 
 
            
 
          }]; 
 
    
 
    [alert addAction:ok]; 
 
    [alert addAction:cancel]; 
 
    
 
    [alert addTextFieldWithConfigurationHandler:^(UITextField * textField) { 
 
     textField.accessibilityIdentifier = @"usernameTextField"; 
 
     textField.placeholder = @"Enter your username"; 
 
     textField.accessibilityLabel = @"usernameLabel"; 
 
    }]; 
 
    
 
    [alert addTextFieldWithConfigurationHandler:^(UITextField * textField) { 
 
     textField.placeholder = @"Enter your password"; 
 
     textField.accessibilityIdentifier = @"paswordTextField"; 
 
     textField.accessibilityLabel = @"passwordLabel"; 
 
    }]; 
 
    
 
    [self presentViewController:alert animated:YES completion:nil]; 
 
    
 
}
와 완전히 IOS에서 사용할 수있는 경고의 유형을 참조하는 프로젝트를 필요로하는 경우, 아래의 URL에서 내 프로젝트를 따르십시오

Alert variations in IOS

0
let alert = UIAlertController(title: "Warning" as String , message: messageString as String, preferredStyle: .Alert) 
     let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) 
     { 
      UIAlertAction in 
       self.dismissViewControllerAnimated(true, completion: nil) 
     } 
     // Add the actions 
     alert.addAction(okAction) 
     self.presentViewController(alert, animated: true, completion: nil) 
관련 문제