我需要在 Tableview 中显示一个自定义 uidropdown。但在 iOS 中,使用 UIPickerView 而不是下拉列表。表视图是根据来自服务器的输入数据动态生成的。它适用于UiTextFields.但是我无法使用它来显示UIPickerView.Plese指导我如何解决此问题。提前谢谢。
编写委托方法UItextFiled
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
[textField resignFirstResponder];
[self setupPicker];
}
并调用setupPicker
方法
-(void)setupPicker
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Set alarm time" message:@"nnnnnnnn" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[alert show];
alert.bounds = CGRectMake(0, 10, 284, 279);
if(!self.datePicker)
{
self.Picker = [[UIPickerView alloc] init];
self.Picker.frame = CGRectMake(20, 45.0, 240.0, 150.0);
self.picker.delegate = self;
self.picker.dataSource = self;
}
[alert addSubview:self.Picker];
}
当您单击UITextFiled
并在警报视图上显示UIPickerView
显示时显示选取器视图的上述代码。