如何在swift中提供自定义单元格中的popover

时间:2016-04-29 11:33:30

标签: swift uitableview uipopovercontroller uipopover

为了呈现popover,我遵循以下代码。

func showPopOver() {
    let secondStoryboard = UIStoryboard(name: "Second", bundle: nil)

    viewObj =  secondStoryboard.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
    viewObj.modalPresentationStyle = UIModalPresentationStyle.Popover
    viewObj.preferredContentSize = CGSizeMake(400,500)

    let popoverPresentationController = viewObj.popoverPresentationController
    popoverPresentationController?.delegate = self
    popoverPresentationController?.sourceView = self.view //walletButton
    popoverPresentationController?.sourceRect = CGRectMake(0, button.frame.origin.y+100, 0, 0)
    presentViewController(viewObj, animated: true, completion: nil)
}

//MARK:- UIPopoverPresentationControllerDelegate methods... starts

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

func prepareForPopoverPresentation(popoverPresentationController: UIPopoverPresentationController) {
    print("prepare for presentation")
}

func popoverPresentationControllerDidDismissPopover(popoverPresentationController: UIPopoverPresentationController) {
    print("did dismiss")
}

func popoverPresentationControllerShouldDismissPopover(popoverPresentationController: UIPopoverPresentationController) -> Bool {
    print("should dismiss")
    return false
}

它在普通视图控制器中工作正常,但我需要在自定义tableview单元格中显示一个弹出视图。

类流程

| - UITableViewController

| -CustomCell:UITableViewCell

| - UIButton:按钮操作 - >这里我们需要显示一个具有3/4帧值的tableview框架的popover。

每当用户点击弹出窗口视图时,都会关闭弹出窗口视图。

0 个答案:

没有答案