Objective c 无法在iOS8上的UIAlertController内显示UIPickerView
之前我使用的是UIactionSheet,但由于它已被弃用,所以我尝试使用UIAlertController来显示UIPicker。 下面是我用来将选择器添加到UIAlertController的代码Objective c 无法在iOS8上的UIAlertController内显示UIPickerView,objective-c,ipad,ios8,uipickerview,uialertcontroller,Objective C,Ipad,Ios8,Uipickerview,Uialertcontroller,之前我使用的是UIactionSheet,但由于它已被弃用,所以我尝试使用UIAlertController来显示UIPicker。 下面是我用来将选择器添加到UIAlertController的代码 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"some_title"
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,但不带拾取器
一个有趣的观察结果是,如果我在中更改preferredStyle
[UIAlertController alertControllerWithTitle:@“一些标题”
消息:无首选样式:UIAlertControllerStyleActionSheet]代码>
从UIAlertControllerStyleActionSheet
到UIAlertControllerStyleAlert
然后我开始获取选择器,但我失去了对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];
我想要控制UIAlertController的位置,因此我使用的是UIAlertControllerStyleActionSheet
以前有人见过这个问题吗?感谢您的帮助。谢谢 我通过在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];