Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
534 views
in Technique[技术] by (71.8m points)

ios - Can we handle the error "Cannot convert the value of type BOOL to expected argument UIiew"

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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:)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...