目标c的新手,这可能是一个简单的错误。我试图解除我UITextField
所有的3个UIPickerView
键盘。因此键盘将不会出现,只会显示选择器视图。我做了一些研究,但无法弄清楚。这是.m文件的代码,它不起作用。
-(void)textFieldDidBeginEditing:(UITextField*)textField;
{
[textField resignFirstResponder];
modeArray = [[NSMutableArray alloc] init];
if(textField.tag==1){
[modeArray addObject:@" bus "];
[modeArray addObject:@" bus/mrt "];
tbMode.inputView = pickerView;
pickerView.hidden = NO;
}
else{
if(textField.tag==2){
[modeArray addObject:@" 300 "];
[modeArray addObject:@" 400 "];
[modeArray addObject:@" 500 "];
tbWalkDist.inputView = pickerView;
pickerView.hidden = NO;
}
else{
if(textField.tag==3){
[modeArray addObject:@" cheapest "];
[modeArray addObject:@" fastest "];
tbRouteOpt.inputView = pickerView;
pickerView.hidden = NO;
}
else{
pickerView.hidden=YES;
}
}
}
}
我应该如何解除只显示选择器视图的键盘?使用此行[textField resignFirstResponder];
我可以使用dimiss键盘吗?
答案 0 :(得分:0)
您需要将所有文本字段委托给viewController,然后使用该方法;
-(BOOL)textFieldShouldReturn:(UITextField *)textField // called from textfield (keyboard)
{
//... place your [textField resignFirstResponder]; logic here
}
确保将文本视图委托协议添加到viewcontroller .h文件
@interface ViewController : UIViewController <UITextViewDelegate>
答案 1 :(得分:0)
我不明白你的问题,但是如果你想这样,如果你按下返回键就会隐藏键盘:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textFieldName resignFirstResponder];
return YES;
}