How do I adjust my popover to the size of the content in my tableview in swift?

后端 未结 6 1100
情话喂你
情话喂你 2021-01-31 03:17

I\'m using popoverPresentationController to show my popover. The UITableViewController used to show as popover is created programmatically and will usu

6条回答
  •  一整个雨季
    2021-01-31 03:41

    Override the preferredContentSize property in your extension of the uitableviewcontroller as following:

    override var preferredContentSize: CGSize {
        get {
            let height = calculate the height here....
            return CGSize(width: super.preferredContentSize.width, height: height)
        }
        set { super.preferredContentSize = newValue }
    }
    

    For calculating the height check out tableView.rectForSection(<#section: Int#>)

提交回复
热议问题