2014-12-29 20 views
15

Tôi cần tạo chế độ xem cửa sổ bật lên mới vì neo không hiển thị trong Trình tạo giao diện trong thời gian biên dịch.Buộc popover trên iPhone với UIPopoverPresentationController được tạo lập trình

Theo this post, việc triển khai phương thức ủy quyền sẽ bắt buộc Popover trên iPhone. (vì lý do tôi không hiểu)

Nó hoạt động tốt khi trên một segue như được hiển thị trong bài viết. Nhưng tôi không thể làm điều này để làm việc theo cách không tách biệt. (Popover hiển thị trên iPad)

Xin vui lòng trợ giúp!

Mã này được liệt kê dưới đây:

func showOptions() { 
    let contentView = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("PasteOption") as NewPasteOptionViewController 
    contentView.modalPresentationStyle = UIModalPresentationStyle.Popover 
    contentView.preferredContentSize = CGSizeMake(200.0, 200.0) 
    presentViewController(contentView, animated: true, completion: nil) 
    var _popoverPresentationController = contentView.popoverPresentationController! 
    _popoverPresentationController.delegate = self 
    _popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirection.Any 
    _popoverPresentationController.sourceView = view 
    _popoverPresentationController.sourceRect = self.navigationItem.titleView!.frame 
} 
// this function below is never called. 
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle { 
    return UIModalPresentationStyle.None 
} 

Ghi chú thêm:

Các trình bày quan điểm điều khiển được trình bày như một tờ dạng phương thức theo quan điểm khác, và gói gọn trong một bộ điều khiển chuyển hướng. Trình điều khiển chế độ xem được trình bày là bộ điều khiển chế độ xem bảng tùy chỉnh.

Trả lời

9

Dường như di chuyển dòng presentViewController(contentView, animated: true, completion: nil) đến cuối hàm sẽ khắc phục sự cố.

+1

Bạn là chính xác. Tò mò rằng tài liệu đã đặt tuyên bố đó đầu tiên (mà đoạn mã cụ thể không có đại biểu thiết lập mặc dù) –

+0

Thiết lập đại biểu nên được đặt trước presentViewController, bạn nghĩ gì? – gabbler

+0

Làm thế nào để bạn mong đợi bản trình bày thành công nếu bạn đặt trình điều khiển bản trình bày sau khi trình bày? –

1
let contentView = 
PLMainNavigationManager.sharedInstance.storyboard.instantiateViewControllerWithIdentifier("PLSearchVCID") as! PLSearchVC 
     contentView.modalPresentationStyle = UIModalPresentationStyle.Popover 
     contentView.preferredContentSize = CGSizeMake(400.0, 500.0) 
     var _popoverPresentationController = contentView.popoverPresentationController! 
     _popoverPresentationController.delegate = self 
     _popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirection.Any 
     _popoverPresentationController.sourceView = self.view 
     _popoverPresentationController.sourceRect = CGRectMake(-30, -280, 320, 400) 
     PLMainNavigationManager.sharedInstance.navigationController?.presentViewController(contentView, animated: true, completion: nil) 
Các vấn đề liên quan