我正在将我的应用程序更新到 iOS 8 并尝试按照此处所述重新创建UIPickerView
内部 a 。使用 Nada Gamal 的答案,我能够重新创建功能,但唯一的响应是在选项卡栏中(即使选项卡栏隐藏在选择器视图后面)。标签栏控制器是根视图控制器。UIActionSheet
UIAlertController
UIPickerView
-(void)loadPickerView{
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
pickerView.backgroundColor = [UIColor whiteColor];
[pickerView selectRow:pickerViewRow inComponent:0 animated:NO];
UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
pickerToolbar.tintColor = self.navigationController.navigationBar.tintColor;
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissActionSheet)];
[barItems addObject:doneBtn];
[pickerToolbar setItems:barItems animated:YES];
UIAlertController * searchActionSheet=[UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
[ searchActionSheet.view setBounds:CGRectMake(8, 208, self.view.frame.size.width, pickerView.frame.size.height+pickerToolbar.frame.size.height)];
[searchActionSheet.view addSubview:pickerToolbar];
[searchActionSheet.view addSubview:pickerView];
[self presentViewController:searchActionSheet animated:YES completion:nil];
}
最后presentViewController
一行中的似乎是问题所在。我尝试了许多不同的方法来让 pickerView 在标签栏区域之外做出响应,包括:
self
self.tabBarController
self.navigationController
(pickerView 根本不显示)[[UIApplication sharedApplication] keyWindow].rootViewController
另一种选择是为此制作一个单独的视图控制器,但我担心这也不起作用,因为UIAlertController
它是 的子类UIViewController
,但也许这是将子视图添加到UIAlertController
.