アプリを iOS 8 に更新し、ここで説明されているようにUIPickerView
内部UIActionSheet
を再作成しようとしています。Nada Gamal からの回答を使用して、機能を再現することができましたが、タブ バー内でのみ応答します (タブ バーはピッカー ビューの後ろに隠れています)。タブ バー コントローラーはルート ビュー コントローラーです。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
もう1つのオプションは、これ用に別のView Controllerを作成することですが、UIAlertController
が のサブクラスであるため、どちらも機能しないことが懸念されますUIViewController
が、おそらくこれは にサブビューを追加する際の問題UIAlertController
です。