2016-09-13 4 views
0

J'ai créé une alerte comme suit:titre UIAlertView et UIAlertController n'affiche pas

// 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]; 

Mais les effets sont comme ceci:

J'essaie de connecter le titre d'alerte, mais le résultat est null:

Comment puis-je résoudre ce problème?

+0

Avant d'essayer de corriger si pour 'UIAlertView': Ne l'utilisez pas. Il est déconseillé dans iOS 8. – FelixSFD

+0

Utilisez-vous setTitle quelque part dans votre code? – vishnuvarthan

+1

goto Produit -> nettoyer et réessayer – KSR

Répondre

0

Les deux sont un travail à mes côtés.

Essayez d'utiliser ce code:

#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

Je crée un nouveau projet (pour iOS7 et versions ultérieures), le code est de travail, mais il ne fonctionne pas dans le projet de l'entreprise. –