1

アプリを iOS 8 に更新し、ここで説明されているようにUIPickerView内部UIActionSheetを再作成しようとしています。Nada Gamal からの回答を使用して、機能を再現することができましたが、タブ バー内でのみ応答します (タブ バーはピッカー ビューの後ろに隠れています)。タブ バー コントローラーはルート ビュー コントローラーです。UIAlertControllerUIPickerView

-(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です。

4

0 に答える 0