UIPickerView仅响应标签栏区域内的响应

时间:2014-10-04 16:24:22

标签: ios objective-c iphone ios8 uialertcontroller

我正在将我的应用更新到iOS 8并尝试使用UIPickerView UIActionSheet重新创建UIAlertController,如here所述。使用Nada Gamal的答案,我能够重新创建功能,但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

另一种选择是为此创建一个单独的视图控制器,但我担心这不会起作用,因为UIAlertControllerUIViewController的子类,但也许这是一个问题将子视图添加到UIAlertController

0 个答案:

没有答案