-3

I am tired of trying to PopOver the view controller and searched every where, tried myself also.This issue has again arrived and i am confused what to do next

func showPopover(base: UIView)
{
    let storyboard : UIStoryboard = UIStoryboard(name: "Messaging", bundle: nil)
    if let viewController = storyboard.instantiateViewControllerWithIdentifier("PreferencesViewController") as?PreferencesViewController
    {
        let navController = UINavigationController(rootViewController: viewController)
        navController.modalPresentationStyle = .Popover

        if let pctrl = navController.popoverPresentationController 
        {
            pctrl.delegate = self

            pctrl.sourceView = base
            pctrl.sourceRect = base.bounds

            self.presentViewController(navController, animated: true, completion: nil)
        }
    }
}

I am calling this method in any one of the actions clicked from UIBarButtons

func optionChoosed(hello:Bool)
{
    if (hello)
    {
        self.showPopover(hello)
    }
}

it says Cannot convert the value of type BOOL to expected argument UIiew.. can we fix this or am i going wrong direction.

Jacopo Penzo
  • 2,168
  • 2
  • 24
  • 29
learn phase
  • 103
  • 10

1 Answers1

0
class SHNewStylesViewController: UIViewController, UIPopoverPresentationControllerDelegate {

var popover: UIPopoverPresentationController? = nil


//MARK: - View life cycle

override func viewDidLoad() {
    super.viewDidLoad()

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}


//MARK: - IBActions

@IBAction func showPopover(sender: AnyObject) {
    let genderViewController = storyboard!.instantiateViewControllerWithIdentifier("ViewControllerTwoIdentifier") as! ViewControllerTwo
    genderViewController.modalPresentationStyle = UIModalPresentationStyle.Popover
    genderViewController.preferredContentSize = CGSize(width: 200.0, height: 400.0) // To change the popover size
    popover = genderViewController.popoverPresentationController!
    popover!.barButtonItem = sender as? UIBarButtonItem
    popover!.delegate = self
    presentViewController(genderViewController, animated: true, completion:nil)
}



//MARK: - Popover Presentation Controller Delegate methods

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
    return UIModalPresentationStyle.None
}

}

In my case showPopover is a IBAction of my bar button item. You can you that code inside the showPopover method wherever you want.

Thanks:)

Karthick Selvaraj
  • 2,387
  • 17
  • 28