我的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];
}
答案 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];