选择器尚未显示
请我花了几个小时来解决这个问题,但没有找到解决方案并向您致辞:)
我有 UIPickerView,当用户单击 UITextField 时,它必须从视图底部显示(这就是我的应用程序要求我必须做的事情) ,所以我实现了这个方法来捕获文本字段的触摸事件:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch;
touch=[touches anyObject];
CGPoint point=[touch locationInView:self.view];
if(CGRectContainsPoint([typeCarburantTextField frame],point))
{
[self pickerTypeCarburantsShow];
}
}
以及这个方法来防止用户单击文本字段时显示键盘:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
return NO;
}
pickerTypeCarburantsShow
-(IBAction)pickerTypeCarburantsShow{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
CGAffineTransform transform=CGAffineTransformMakeTranslation(0, 240);
pickerViewTypesCarburants.transform=transform;
[self.view addSubview:pickerViewTypesCarburants];
[UIView commitAnimations];
}
所有我的IB连接非常好,但是当我运行并单击 UITextField 时,键盘不会出现但我没有看到选择器显示 请帮忙,提前谢谢:)
please i have hours with this issue without founding solution and adressing to you for that :)
i have UIPickerView which has to be displayed from the bottom of the view when the user click on a UITextField (that's what my app requirement oblige me to do), so i implement this method to catch the touch event of the text field :
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch;
touch=[touches anyObject];
CGPoint point=[touch locationInView:self.view];
if(CGRectContainsPoint([typeCarburantTextField frame],point))
{
[self pickerTypeCarburantsShow];
}
}
and this method to prevent the keyboard from being displayed when the user click on the text field :
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
return NO;
}
pickerTypeCarburantsShow
-(IBAction)pickerTypeCarburantsShow{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
CGAffineTransform transform=CGAffineTransformMakeTranslation(0, 240);
pickerViewTypesCarburants.transform=transform;
[self.view addSubview:pickerViewTypesCarburants];
[UIView commitAnimations];
}
all my IB connections are pretty good, however when i run and i click the UITextField the keyboard doesn't appear but i don't see the picker showed
pleaaaase help, thx in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可能想要的可能是这个。
UITextField 有这个属性,
inputView
当文本字段成为第一响应者时要显示的自定义输入视图。
讨论
如果此属性中的值为 nil,则文本字段在成为第一响应者时显示标准系统键盘。将自定义视图分配给此属性会导致显示该视图。
该属性的默认值为 nil。
因此,要显示另一个视图而不是键盘,所需要做的就是设置该视图,在本例中将 uipickerview 或其容器设置为文本字段的 inputView...
例如,要显示一些 pickerview 而不是键盘,你可能想要
What you might want is probably this one..
The UITextField has this property,
inputView
The custom input view to display when the text field becomes the first responder.
Discussion
If the value in this property is nil, the text field displays the standard system keyboard when it becomes first responder. Assigning a custom view to this property causes that view to be presented instead.
The default value of this property is nil.
So, to display another view instead of the keyboard, all that is required is to set that view, in this case the uipickerview or its container as the inputView for the textfield...
for example, to show some pickerview instead of the keyboard, you might want to
您的 PickerView 是否同时设置了委托和数据源?否则不会显示出来。
Does your PickerView have both its Delegate and DataSource set? It won't show up otherwise.
我的问题解决了,所以问题出在 UITextField 委托方法中,我实现了错误的方法:
相反,应该是这个方法来显示 UIPickerView :
其中
pickerTypeCarburantShow
是一个 IBAction 方法,应该是动画整个 UIPickerView 视图..希望这可以帮助那些在同一问题上苦苦挣扎的人:)my problem was resolved, so the problem was in the UITextField delegate method, i have implemented the wrong method :
instead, it should be this method to show the UIPickerView :
where
pickerTypeCarburantShow
is an IBAction method which is supposed to animate the whole UIPickerView view.. hope this help who is struggling in the same issue :)