2014-10-07 20 views
11

iOS 7'de mükemmel şekilde gösterilen bir UIAlertView'ım var ancak iOS 8'de herhangi bir düğme veya etiket göstermiyor. Uyarı hala görülebilir ancak sadece küçük bir beyaz kutu. Tamam ve iptal düğmeleri olaylarını da alır, ancak metin görünmez.iOS 8: UIAlertView/UIAlertController metin veya düğmeleri göstermiyor

Ben iOS 8'de çerçeveyi kontrol

- (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]; 
} 

bir düğmeye tıklandığında göstermek için bu uyarıyı kullandık: Bu veriyor (0,0,0,0) ancak iOS 7'de bu veriyor kesin bir değer.

Ayrıca uialertview'in alt görünümlerini yinelemek için kontrol ettim. IOS7'de, alert’in alt görünümlerini bulduğu için döngüde yer alır. IOS8'de, alertView'ın alt görünümleri olmadığını söylüyor.

+0

Bu gerçek kod mu? Gerçek kodu yazmazsa gönderin. – rmaddy

+0

@siddhant gerçek kodu gönderir. Bu kod iOS 8'de de çalışıyor. Bu nedenle, projenize yazdığınız kodu kopyalayın. – Jasmeet

+0

bu http://stackoverflow.com/questions/25927676/uialertview-title-not-display/25928050#25928050 –

cevap

4

Sorunumun cevabını aldım. Sorun projemde UIFont + Replacement kategorisini kullanmam oldu. Bu iOS 7'de iyi çalışıyordu, ancak iOS 8'de birkaç kullanım dışı yöntem kullanıyordu. Bu nedenle nedenini bilmiyorum, ancak yalnızca uyarı görünümümde herhangi bir etiket gösterilmiyordu.

Çözüm: Proje kategorisini sildiniz ve xib ile yazı tipini ayarlayınız. Proje çalışma alanımızdaki herhangi bir yazı tipinin .tff dosyasını yerleştirdikten sonra, özel fontlar altında xib'deki yazı tipi adlarını görürüz. UIFont + Replacement kategorisini KULLANMAYINIZ.

+0

Çalışıyor: D. Çok teşekkür ederim Siddhant. Çıldırıyordum! –

+1

@AlexGuerra - Rica ederim. Garip bir konu ve daha garip bir çözüm :) – Siddhant

-5

Bu, UIAlertview Sorunları değil. bu çalışma cezası kontrol ediniz .. ben senin kodu sorunlarını düşünmek

...........

altındaki Beğen viewDidLoad Bu kodu herhangi view controller yılında:

- (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''dan uyarı gösterme. Görünüm henüz gösterilmiyor. 2) Bu soruya nasıl cevap veriyor? OP, kodun iOS 7 altında çalıştığını bildirir, böylece uyarının gösterildiği yerde bir sorun olmaz. – rmaddy

+0

@rmaddy - Alert hala iOS8'de gösteriliyor ancak metin veya düğme etiketi gösterilmiyor. Çerçeveyi kontrol ettim ... (0,0,0,0) – Siddhant

+0

@ Siddhant Bu bilgiyi, bu ilgisiz cevabı değil, sorunuza ekleyin. – rmaddy

2

iOS 8'de, UIAlertcontroller ile UIAletrview ve UIActionSheet'u değiştirmeniz gerekir.

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

UIAlertView fazla bilgi için iOS 8'den kullanımdan kaldırıldı bu

ziyaret edin: Sen
Apple Alertcontroller mesajın yerine başlık ayarlayabilirsiniz iOS 8 ile

12

ilk elma forumda bu belgeleri okuyun http://nshipster.com/uialertcontroller/. iOS 7 ve iOS 8 için ayrı kod yazmak gidiyoruz https://developer.apple.com/LIBRARY/IOS/documentation/UIKit/Reference/UIAlertViewDelegate_Protocol/index.html

Yani, yerine UIAlertController kullanarak edilmelidir:

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

Bu, soruyu cevaplamaya teşebbüs etmiyor. OP, iOS 8 altında “UIAlertView” ile hala mükemmel bir başlık ve mesaj istiyor. – rmaddy

29

kontrol sınıf varsa

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

O kod

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

aşağıda uyarılarına alanlar ve düğmeler eklemek için nasıl anlamak için kod üzerinden okuyunuz kontrol edebilirsiniz.

- (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]; 
 
    
 
}
ve tamamen IOS mevcuttur Uyarıları türlerini başvurmak için bir proje gerekiyorsa, aşağıdaki URL'den projemi takip edin:

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)