2016-06-09 4 views
0

Я новичок в Xcode (7.3) и ИОС (9.3) .Я попробовал пример проекта, чтобы отобразить предупреждающее сообщение, но я получил сообщение об ошибке, как:у меня нет ошибки: нет видимого интерфейса для «UIAlertController»

«нет виден интерфейс для «UIAlertController» объявляет «show'.Belo я прикрепил код.

//ViewController.m// 

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert" 
                 message:@"This is an alert." 
                 preferredStyle:UIAlertControllerStyleAlert]; 

UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault 
                 handler:^(UIAlertAction * action) {}]; 
[alert show]; 


//AppDelegate.h// 


@interface AppDelegate : UIResponder <UIApplicationDelegate> 

@property (strong, nonatomic) UIWindow *window; 
@end. 

пожалуйста, помогите мне.

+0

Подсказка - где в документации для 'UIAlertController' вы видите метод' show'? – rmaddy

ответ

0

Вы делаете это неправильно. шоу доступен только для UIAlertVIew но не UIAlertAction.

UIALertAction это действие добавляется к UIAlertController

1

Попробуйте вместо этого:

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert" 
                message:@"This is an alert." 
                preferredStyle:UIAlertControllerStyleAlert]; 

UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault 
                handler:^(UIAlertAction * action) {}]; 

[alert addAction:defaultAction]; 
[self presentViewController:alert animated:YES completion:nil]; 
+0

Я попробовал эту опцию, теперь ошибка не появляется, но предупреждение не отображается. –

+0

это означает, что что-то не так где-то в другом месте –

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