如何将UITableViewController显示为UIPopover ViewController

时间:2016-05-09 08:35:03

标签: swift uitableview uipopovercontroller

我需要使用tableview控制器显示弹出窗口。

我使用以下代码来展示

func showPopOver(){

让secondStoryboard = UIStoryboard(名称:" 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方法......开始

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

就像UIViewController那样现在我试图加载UITableViewController,但它无法正常工作。显示UIPopover但未显示tableview。

请建议我 谢谢你提前

1 个答案:

答案 0 :(得分:4)

func showPopOver() {

    let tableViewController = UITableViewController()
    tableViewController.modalPresentationStyle = UIModalPresentationStyle.Popover
    tableViewController.preferredContentSize = CGSizeMake(200, 250)
    tableViewController.tableView=FontTable

    presentViewController(tableViewController, animated: true, completion: nil)

    let popoverPresentationController = tableViewController.popoverPresentationController
    popoverPresentationController?.sourceView = sender as! UIButton
    popoverPresentationController?.sourceRect = CGRectMake(0, 0, sender.frame.size.width, sender.frame.size.height)
    popoverPresentationController?.delegate=self
    popoverPresentationController?.permittedArrowDirections=UIPopoverArrowDirection.Up
}

func prepareForPopoverPresentation(popoverPresentationController: UIPopoverPresentationController)
{
}

func popoverPresentationControllerDidDismissPopover(popoverPresentationController: UIPopoverPresentationController)
{
}

func popoverPresentationControllerShouldDismissPopover(popoverPresentationController: UIPopoverPresentationController) -> Bool
{
    return true
}