【问题标题】:Not able to show UIPickerView inside UIAlertController on iOS8无法在 iOS8 上的 UIAlertController 中显示 UIPickerView
【发布时间】:2014-11-04 13:12:01
【问题描述】:

之前我使用的是 UIactionSheet,但由于它已被弃用,我正在尝试使用 UIAlertController 来显示 UIPicker。 这是我用来将选择器添加到 UIAlertController 的一段代码。

        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"some_title"
                                                                             message:nil
                                                                      preferredStyle:UIAlertControllerStyleActionSheet];
    [alertController setModalPresentationStyle:UIModalPresentationPopover];
    [alertController.view addSubview:_formatPickerView];
    UIPopoverPresentationController *popPresenter = [alertController
                                                     popoverPresentationController];
    // cell is a cell from a tableview
    popPresenter.sourceView = cell;
    popPresenter.sourceRect = cellRect;
    [self presentViewController:alertController animated:NO completion:nil];

这会调出 AlertController 但没有 Picker。

一个有趣的观察是,如果我在

中更改 preferredStyle

[UIAlertController alertControllerWithTitle:@"some_title" message:nil preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertControllerStyleActionSheetUIAlertControllerStyleAlert 然后我开始获取 Picker 但我失去了对 UIAlertController 位置的控制。

我想要控制 UIAlertController 的位置,所以我使用UIAlertControllerStyleActionSheet

以前有人见过这个问题吗?任何帮助表示赞赏。谢谢!

【问题讨论】:

    标签: objective-c ipad ios8 uipickerview uialertcontroller


    【解决方案1】:

    我通过在UIActionSheet 中显示UIPickerView 解决了这个问题。

    UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:@"\n\n\n\n\n\n\n\n\n\n"
                                                                 delegate:nil
                                                        cancelButtonTitle:nil
                                                   destructiveButtonTitle:nil
                                                        otherButtonTitles:nil];
        actionSheet.delegate = self;
        [actionSheet addSubview:_formatPickerView];
        UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
        CGRect cellRect = cell.bounds;
        cellRect.size.width = cell.frame.size.width * 2;
        cellRect.origin.x = -(cell.frame.size.width/2);
    
        [actionSheet showFromRect:cellRect inView:cell animated:YES];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-31
      • 2023-04-02
      • 1970-01-01
      • 2015-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-27
      相关资源
      最近更新 更多