iOS8 AlertViewController问题

时间:2014-09-18 07:43:05

标签: ios8 uialertcontroller

我的textField中有一个viewController,当AlertViewController出现时,键盘未出现在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];
 }

1 个答案:

答案 0 :(得分: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];