2015-07-04 34 views
5

Tôi đang cố gắng hiển thị chế độ xem theo chương trình thông qua cửa sổ bật lên thích ứng (ví dụ: trong cửa sổ bật lên trên iPad, toàn màn hình trên iPhone). Để có thể loại bỏ các điều khiển xem trình bày trên iPhone, tôi đã cố gắng gói nó trong một bộ điều khiển chuyển hướng như trong https://stackoverflow.com/a/29956631/5061277 hoặc ví dụ tốt đẹp ở đây: https://github.com/shinobicontrols/iOS8-day-by-day/tree/master/21-alerts-and-popovers/AppAlert, trông giống như:Tại sao không phải là presentationController: viewControllerForAdaptivePresentationStyle: được gọi?

import UIKit 

class ViewController: UIViewController, UIPopoverPresentationControllerDelegate { 

    @IBAction func handlePopoverPressed(sender: UIView) { 
    let popoverVC = storyboard?.instantiateViewControllerWithIdentifier("codePopover") as! UIViewController 
    popoverVC.modalPresentationStyle = .Popover 
    // Present it before configuring it 
    presentViewController(popoverVC, animated: true, completion: nil) 
    // Now the popoverPresentationController has been created 
    if let popoverController = popoverVC.popoverPresentationController { 
     popoverController.sourceView = sender 
     popoverController.sourceRect = sender.bounds 
     popoverController.permittedArrowDirections = .Any 
     popoverController.delegate = self 
    } 
    } 

    func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle { 
    // This line _IS_ reached in the debugger 
    NSLog("Delagate asked for presentation style"); 
    return .FullScreen 
    } 

    func presentationController(controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? { 

    // This line _IS_NOT_ reached in the debugger 
    NSLog("Delegate asked for view controller"); 
    return UINavigationController(rootViewController: controller.presentedViewController) 


    } 
} 

Trong khi adaptivePresentationStyleForPresentationController phương thức ủy nhiệm được gọi, phương thức presentationController viewControllerForAdaptivePresentationStyle delegate không được gọi. Kết quả là không có cách nào để loại bỏ trình điều khiển được trình bày trên iPhone.

Tôi đã thử XCode 6.4 và 7.0b2 trên iOS 8.1 đến 8.4, cả trong trình mô phỏng và trên thiết bị, và trong mọi trường hợp, đại biểu của tôi đã yêu cầu viewControllerForAdaptivePresentationStyle. Tại sao? Có một thiết lập xây dựng tôi nên được xem xét, hoặc có thể có cài đặt XCode 7 được thay đổi một cái gì đó? Mã chính xác này được trình bày như là làm việc trong các liên kết ở trên.

Trả lời

0

Bạn cần phải thêm phương pháp này:

-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection{ 
    return UIModalPresentationOverFullScreen; 
} 
1

Bạn cần phải trình bày nó sau khi cấu hình nó. Hoặc sử dụng một segue để làm cho nó dễ dàng hơn nhiều.

+0

Mặc dù tài liệu ngụ ý khác, popoverPresentationController phải ủy quyền cấu hình trước khi bạn gọi hiện tại hoặc viewControllerForAdaptivePresentationStyle sẽ không bao giờ được gọi. – stevex

Các vấn đề liên quan