xcode 当用户做出选择时如何隐藏 UIPickerView
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13858679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to hide a UIPickerView when the user make its choice
提问by TheInterestedOne
I've created a custom UIPickerView with the following code
我使用以下代码创建了一个自定义 UIPickerView
UIPickerView *picker =[[UIPickerView alloc] initWithFrame:CGRectMake(139,50,161,30)];
picker.delegate=self;
picker.showsSelectionIndicator=YES;
picker.hidden=NO;
[self.view addSubview:picker];
Now I want to hide the pickerView when the user make its choice of a row simply with
现在我想在用户简单地选择一行时隐藏pickerView
picker.hidden=YES;
Now: 1) How can I recognize the choice of the user and then hide the unuseful pickerview? 2) Can I show the choice in a TextField? with @"choice"?
现在: 1) 如何识别用户的选择,然后隐藏无用的选择器视图?2) 我可以在 TextField 中显示选择吗?与@“选择”?
采纳答案by Pétur Ingi Egilsson
I'm using a UIPickerView as the inputView for a TextField (thus replacing the onscreen keyboard). I use the following delegate to dismiss the view.
我使用 UIPickerView 作为 TextField 的 inputView(从而替换了屏幕键盘)。我使用以下委托来关闭视图。
#pragma mark - UIPickerViewDelegate
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
// Code logic
[[self view] endEditing:YES];
}
回答by Inder Kumar Rathore
Add this line where you have created picker
在您创建选择器的位置添加此行
picker.delegate = self;
your callback
你的回电
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
picker.hidden=YES;
}
回答by Paras Joshi
use the delegate method of UIPickerView
like bellow..
使用UIPickerView
像下面这样的委托方法..
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
yourTextField.text = [yourArray objectAtIndex:row];
thePickerView.hidden = YES;
}
Also you can take one UIButton
and hide this with action event of UIButton
.
你也可以拿一个UIButton
并用动作事件隐藏它UIButton
。
回答by Shashank Kulshrestha
You can use UINavigationBar and Barbutton with cancel and Done text upon it.
您可以使用带有取消和完成文本的 UINavigationBar 和 Barbutton。
You can refer the following link
你可以参考以下链接
Objective C implementing a UIPickerView with a "Done" button
回答by Ankit Goyal
UIView *addMealView; // here i am showing my picker
UIView *addMealView; // 这里我展示了我的选择器
- (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)component
{
[addMealView endEditing:YES];
}
回答by 5573352
I'm using a UIPickerView as the inputView for a TextField (for replacing the standard keyboard). I use the ResignFirstResponder (TextField method) to dismiss the view.
我使用 UIPickerView 作为 TextField 的 inputView(用于替换标准键盘)。我使用 ResignFirstResponder(TextField 方法)关闭视图。