2016-09-13 1 views
0

ich eine Warnung erstellt haben, wie folgt:UIAlertView und UIAlertController Titel nicht angezeigt

// UIAlertView 
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"WARNING" message:@"Are you sure you want to quit ?" delegate:nil cancelButtonTitle:@"Confirm" otherButtonTitles:@"Cancel", nil]; 
[alertView show]; 

// or UIAlertController 
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"WARNING" message:@"Are you sure you want to quit ?" preferredStyle:UIAlertControllerStyleAlert]; 
[alertController addAction:[UIAlertAction actionWithTitle:@"Confirm" style:UIAlertActionStyleDefault handler:NULL]]; 
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:NULL]]; 
[self presentViewController:alertController animated:YES completion:NULL]; 

Aber sowohl die Effekte sind wie folgt aus:

Ich versuche, den Titel Benachrichtigung anmelden, aber das Ergebnis ist null:

Wie kann ich das beheben?

+0

Bevor Sie, wenn für 'UIAlertView' zu beheben versuchen: Verwenden Sie es nicht. Es ist in iOS 8 veraltet. – FelixSFD

+0

Verwenden Sie SetTitle irgendwo in Ihrem Code? – vishnuvarthan

+1

goto Produkt -> sauber und versuchen Sie es erneut – KSR

Antwort

0

Beide von ihnen arbeiten in meiner Seite.

Versuchen Sie diesen Code zu verwenden:

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"WARNING" message:@"Are you sure you want to quit ?" delegate:nil cancelButtonTitle:@"Confirm" otherButtonTitles:@"Cancel", nil]; 
    [alertView show]; 

    [self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(grHandler)]]; 
} 

-(void)grHandler{ 
    // UIAlertController 
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"WARNING" message:@"Are you sure you want to quit ?" preferredStyle:UIAlertControllerStyleAlert]; 
    [alertController addAction:[UIAlertAction actionWithTitle:@"Confirm" style:UIAlertActionStyleDefault handler:NULL]]; 
    [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:NULL]]; 
    [self presentViewController:alertController animated:YES completion:NULL]; 
} 

@end 
+0

Ich ein neues Projekt erstellen (für iOS7 und höher), der Code ist Arbeit, aber es funktioniert nicht in der Projekt der Firma. –

Verwandte Themen