如何在iOS 8的iPhone版Popover中呈现UIAlertController

时间:2014-11-23 05:34:24

标签: ios8 xcode6 uipopovercontroller uialertcontroller

我想从导航栏的标题中显示一个弹出窗口,该标题已成功配置为具有多个选项的按钮,例如iPhone应用程序上的警报控制器。点击标题时会调用以下代码,但它会在底部显示操作表而不是弹出窗口。你能帮我找到什么问题吗?感谢。

UIAlertController * alertController = [UIAlertController alertControllerWithTitle: nil
                                                                          message: nil
                                                                   preferredStyle: UIAlertControllerStyleActionSheet];
[alertController addAction: [UIAlertAction actionWithTitle:@"Close" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    // dismiss viewcontroller
    [self dismissViewControllerAnimated:YES completion:nil];
}]];
[alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    // Handle Cancel
    // do nothing
}]];

alertController.modalPresentationStyle = UIModalPresentationPopover;
alertController.preferredContentSize = CGSizeMake(250.0, 180.0);

UIPopoverPresentationController *popoverPresentation = alertController.popoverPresentationController;
popoverPresentation.sourceRect = self.parentViewController.navigationItem.titleView.frame;
popoverPresentation.sourceView = self.view;
popoverPresentation.permittedArrowDirections = UIPopoverArrowDirectionUp;
popoverPresentation.delegate = self;

[self presentViewController: alertController animated: YES completion: nil];

0 个答案:

没有答案