2014-11-23 5 views
0

Я хочу показать popover из заголовка навигационной панели, который успешно настроен как кнопка с несколькими вариантами, такими как Alert Controller в приложении iPhone. Следующий код вызывается, когда заголовок используется, но он показывает лист действий внизу, а не popover. Можете ли вы помочь мне найти, что случилось? Благодарю.Как представить UIAlertController в Popover для iPhone с iOS 8

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

Вы не можете сделать это с кодом (программно) с UIAlertController, как это не имеет никакого popoverPresentationController на iPhone. Он доступен только в iPad.

UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:PDFDataArray applicationActivities:nil]; 

if ([activityVC respondsToSelector:@selector(popoverPresentationController)]) { 
    NSLog(@"Popover available for this device type"); 
}  

Я успешно представил Popovers на iPhone в прошлом, используя адаптивный стиль SEGUE Present As Popover в интерфейсе-строитель/раскадровке и реализации методу adaptivePresentationStyleForPresentationController делегата возвращать правильные UIModalPresentationStyle. Вы также можете попробовать этот подход.

Смежные вопросы