2016-09-13 3 views
0

Я создал предупреждение следующим образом:UIAlertView и UIAlertController название не отображается

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

Но оба эти эффекты, как это:

Я пытаюсь войти название предупреждения, но результат is null:

Как это исправить?

+0

Перед тем, как попытаться исправить, если для 'UIAlertView': Не используйте его. Это устарело в iOS 8. – FelixSFD

+0

Вы используете setTitle где-то в своем коде? – vishnuvarthan

+1

goto Продукт -> очистите и попробуйте еще раз – KSR

ответ

0

Оба они работают на моей стороне.

Попробуйте использовать этот код:

#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

Я создаю новый проект (для iOS7 и более поздних версий), код работает, но он не работает в проект компании. –

Смежные вопросы