【发布时间】:2015-04-30 19:52:03
【问题描述】:
我注意到一些非常奇怪的行为。我想在选择 UITextField 时显示 UIAlertView:
[self.addressTextField addTarget:self action:@selector(addressTextFieldSelected) forControlEvents:UIControlEventEditingDidBegin];
被调用的方法是:
- (void)addressTextFieldSelected {
if (!geoPoint) {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Text" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertView show];
}
}
当触摸 textField 时,键盘确实开始向上滑动。然而,当 alertView 出现时,键盘消失。选择“确定”并关闭 alertView 后,文本字段的键盘会向上滑动。
编辑
在其他人的帮助下,我创建了这个工作,虽然我对键盘一开始就消失有点不满意。
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
if (textField.tag == 2) {
if (!geoPoint && !justShowedGeoPointAlert) {
showingGeoPointAlert = YES;
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Make sure to geotag this address." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertView show];
return NO;
} else {
justShowedGeoPointAlert = NO;
}
}
return YES;
}
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {
if (showingGeoPointAlert) {
justShowedGeoPointAlert = YES;
showingGeoPointAlert = NO;
[self.addressTextField becomeFirstResponder];
}
}
【问题讨论】:
-
那么你想在你的应用中做什么?同时使用键盘和 AlertView?
-
@BC_Dlium 我想要 1:alertView 出现并且键盘根本不会向上滑动,直到 alertView 被解除或 2:键盘在 alertView 启动并停留在那里时出现。现在键盘向上滑动然后消失,它看起来确实有问题。
标签: ios objective-c uitextfield uialertview