UIPopoverController, Xcode 6, IOS 8 using Swift

前端 未结 3 1641
粉色の甜心
粉色の甜心 2021-02-04 22:13

I\'m having some trouble getting a UIPopover to appear using swift. The code that is commented out works fine in Objective-C, but doesn\'t work using Swift. When I tap the + in

3条回答
  •  走了就别回头了
    2021-02-04 22:50

    Here is a simple example for iOS 8. Popover are presented using adaptivity apis in iOS 8.

    class PlayerInformationTableViewController: UITableViewController, UIPopoverPresentationControllerDelegate, NSFetchedResultsControllerDelegate{
    
       ...
    
    
      @IBAction func addPopover(sender: UIBarButtonItem){
        let playerInformationViewController =  PlayerInformationViewController()
        playerInformationViewController.modalPresentationStyle = .Popover
        playerInformationViewController.preferredContentSize = CGSizeMake(300, 300)
    
    
    
        let popoverPresentationViewController = playerInformationViewController.popoverPresentationController
        popoverPresentationViewController?.permittedArrowDirections = .Any
        popoverPresentationViewController?.delegate = self
        popoverPresentationController?.barButtonItem = sender
        presentViewController(playerInformationViewController, animated: true, completion: nil)
      }
    
    
      func adaptivePresentationStyleForPresentationController(controller: UIPresentationController!) -> UIModalPresentationStyle{
        return .None
      }
    
    }
    

提交回复
热议问题