Используйте UIAlertView и UIAlertController для одного и того же приложения.

Я хочу отобразить предупреждение. Но поскольку uialertView устарел для iOS 8, что я могу сделать, чтобы отобразить предупреждение для обоих типов ОС?


person abonos App    schedule 13.10.2014    source источник
comment
возможный дубликат отображение оповещения с iOS7, iOS8   -  person gsanllorente    schedule 14.10.2014
comment
Дублируется... Это то, что я искал. Благодарю вас!   -  person abonos App    schedule 24.10.2014


Ответы (1)


Попробуйте этот фрагмент кода, чтобы отобразить оповещение в iOS8. Это определенно сработает.


- (IBAction)btn1Clicked:(UIButton *)sender {

// Стиль предупреждения
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"ALERT!" сообщение:@"Что ты будешь делать?" preferredStyle:UIAlertControllerStyleAlert];

__weak ViewController *wself = self;

// Make choices for the user using alert actions.
**UIAlertAction** *doSomethingAction = [UIAlertAction actionWithTitle:@"I'm doing something" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
    __strong ViewController *sself = wself;
    sself.alertResponseLabel.text = @"You did something!";
}];

 UIAlertAction *doNothingAction = [UIAlertAction actionWithTitle:@"I'm totally ignoring this" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    __strong ViewController *sself = wself;
    sself.alertResponseLabel.text = @"OK, just ignore me...";
}];

// Add actions to the controller so they will appear
[**alert addAction:doSomethingAction];
[alert addAction:doNothingAction];**
 alert.view.tintColor = [UIColor blackColor];
**[self presentViewController:alert animated:YES completion:nil];**  }
person Alen Alexander    schedule 23.10.2014