0
我想從導航欄的標題中顯示彈出窗口,該窗口已成功配置爲具有多種選擇的按鈕,如iPhone應用程序上的Alert Controller。當輕擊標題時會調用以下代碼,但它會在底部顯示操作表而不是彈出窗口。你能幫我找到問題嗎?謝謝。如何在iPhone上使用iOS 8在彈出窗口中顯示UIAlertController
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];