我已经覆盖了UIViewController中的-inputAccessoryView:
方法,该方法返回一个显示在键盘顶部的视图,该视图在viewController视图上编辑UITextField
时显示。
-(UIView *)inputAccessoryView;
我还在viewController中展示了一个UIAlertController。
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Save Profile" message:@"You have made changes to your profile. Do you want to save them?" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
[alert addAction:[UIAlertAction actionWithTitle:@"Save" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//Code to save the profile.
}]];
[self presentViewController:alert animated:YES completion:nil];
如您所见,我没有将任何textField添加到UIAlertController。
奇怪的是,当呈现UIAlertController时,inputAcessoryView会出现在屏幕的底部。
这是一个错误,还是我忽略了什么?
答案 0 :(得分:1)
将输入附件视图重命名为inputAccessoryView
以外的其他视图。
例如keyboardaccessoryView。
然后添加以下行
self.m_textFieldName.inputAccessoryView = [self keyboardInputAccessoryView];
这解决了我的问题。
答案 1 :(得分:0)
请勿使用名称' inputAccessoryView'
这将解决..!
- (UIView *)CustominputAccessoryView {
if (!keyboardinputAccessoryView) {
CGRect accessFrame = CGRectMake(0.0, 0.0, [UIScreen mainScreen].bounds.size.width, 40.0);
keyboardinputAccessoryView = [[UIView alloc] initWithFrame:accessFrame];
keyboardinputAccessoryView.backgroundColor = [UIColor colorWithRed:0/255.0f green:0/255.0f blue:0/255.0f alpha:0.6];
UIButton *compButton = [UIButton buttonWithType:UIButtonTypeCustom];
compButton.frame = CGRectMake([UIScreen mainScreen].bounds.size.width-60, 0.0, 50, 40.0);
[compButton setTitle: @"Done" forState:UIControlStateNormal];
compButton.titleLabel.textColor = [UIColor blueColor];
[compButton setTitleColor:self.view.tintColor forState:UIControlStateNormal];
[compButton addTarget:self action:@selector(completeCurrentWord:)
forControlEvents:UIControlEventTouchUpInside];
[keyboardinputAccessoryView addSubview:compButton];
}
return keyboardinputAccessoryView;
}
keyboardinputAccessoryView 只是一个UIView
@property (readonly, retain) UIView *keyboardinputAccessoryView;
然后制作' CustominputAccessoryView'作为textField的inputAccessoryView
- (void)textFieldDidBeginEditing:(UITextField *)textField {
textField.inputAccessoryView = [self CustominputAccessoryView];
}
答案 2 :(得分:0)
遇到同样的问题,你可以试试
textFirld.resignFirstResponder()
在呈现AlertViewController之前。
它对我有用。
答案 3 :(得分:-1)
你有UITextField的属性,比如inputAccessoryView,所以它已经过了它。如果可能的话
只需更改视图名称
即可-(UIView *)inputAccessoryView;
到某个名字
-(UIView *)alertDisplayView;
这将解决..!我不知道你为什么用名称inputAccessoryView来获取视图..!
希望它可以帮助你......!