Ios 当我点击UIExtField时,如何显示UIPickerView?

Ios 当我点击UIExtField时,如何显示UIPickerView?,ios,cocoa-touch,uitextfield,uipickerview,Ios,Cocoa Touch,Uitextfield,Uipickerview,我从网上找到了很多示例代码,但也不起作用。。。。任何人都可以告诉我下面的代码有什么问题吗?谢谢。求救 //我的存储板屏幕 //这是PickerViewTest.h @接口InputRound:UIViewController { UIPickerView*pvPickerTest; NSMutableArray*aryMaster; } @属性(非原子,保留)IBUIPickerView*pvPickerTest; @属性(非原子,保留)NSMutableArray*aryMaster; @结

我从网上找到了很多示例代码,但也不起作用。。。。任何人都可以告诉我下面的代码有什么问题吗?谢谢。求救

//我的存储板屏幕

//这是PickerViewTest.h
@接口InputRound:UIViewController
{
UIPickerView*pvPickerTest;
NSMutableArray*aryMaster;
}
@属性(非原子,保留)IBUIPickerView*pvPickerTest;
@属性(非原子,保留)NSMutableArray*aryMaster;
@结束
//这是PickerViewTest.m
@接口InputRound()
@结束
@实现PickerViewTest
@合成pvPickerTest,aryMaster;
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
//自定义初始化
}
回归自我;
}
-(无效)viewDidLoad
{
[超级视图下载];
//加载视图后执行任何其他设置。
aryMaster=[[NSMutableArray alloc]init];
[aryMaster addObject:@“User01”];
[aryMaster addObject:@“User02”];
[aryMaster addObject:@“User03”];
}
-(NSInteger)部件编号PickerView:(NSInteger)部件
{
返回1;
}
-(NSInteger)选择器视图:(UIPickerView*)选择器行数组件:(NSInteger)组件
{
返回[主机计数];
}
-(NSString*)pickerView:(UIPickerView*)PickerTitleForrow:(NSInteger)组件行:(NSInteger)组件
{
返回[aryMaster objectAtIndex:row];
}
-(无效)视图卸载
{
[超级视频下载];
//释放主视图的所有保留子视图。
}
-(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation
{
返回(interfaceOrientation==UIInterfaceOrientationGraphic);
}
-(BOOL)textField应该开始编辑:(UITextField*)textField
{
//显示UIPickerView
pvPickerTest.frame=CGRectMake(0,500,pvPickerTest.frame.size.width,pvPickerTest.frame.size.height);
[UIView beginAnimations:nil上下文:NULL];
[UIView setAnimationDuration:.50];
[UIView setAnimationDelegate:self];
pvPickerTest.frame=CGRectMake(0,200,pvPickerTest.frame.size.width,pvPickerTest.frame.size.height);
[self.view addSubview:pvPickerTest];
[UIView委员会];
返回否;
}
@结束

不要试图通过滚动自己的外观动画来模仿内置动画来重新发明轮子。将选择器视图设置为文本字段的输入视图,系统将为您制作动画:

textField.inputView = pickerView;

当您开始编辑文本字段时,选择器将在屏幕上为您设置动画。有关更多详细信息,请参见我的答案,包括在顶部添加带有“完成”按钮的工具栏

是否已将UITextFieldDelegate添加到.h和UITextField?请在textFieldDidBegin中编写代码,并在出现时为delegatesHow i remove动画
textField.inputView = pickerView;