2

我有一个textFieldviewControllerAlertViewController出现键盘时,AlertViewController 的背景中没有出现。但是在关闭AlertViewController键盘后出现。这件事只发生在 ios8 设备上。这是我的以下代码:

 [textField becomeFirstResponder];

 if([self checkIfiOS8])
 {
          // for iOS 8 
          UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Your Title"
                                                                               message:@"Your message" preferredStyle:UIAlertControllerStyleAlert];
          UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }];
          [alert addAction:cancelAction];
          [self presentViewController:alert animated:YES completion:nil];

 }
 else
 {
           // iOS7
           UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Your Title" message:@"Your message" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
           [alert show];
           [alert release];
 }
4

1 回答 1

2
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"AlertView" message:@"I am an AlertView" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction * action) {
                                                          [alert dismissViewControllerAnimated:YES completion:nil];
                                                      }];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
于 2014-09-18T08:23:29.923 回答