ios - 调整弹出窗口 ViewController 的大小以适应要在 UITableView 中显示的数据

标签 ios swift tableview viewcontroller popover

我正在开发一个有两个 View Controller 的应用程序。第一个是当用户在 TextField 上执行长按手势时显示弹出 ViewController(用于第二个 View Controller)。下面是以编程方式完成的弹出窗口代码(在第一个 View Controller 中):

        func longpressGestureTriggeredForIndicativeDesignWorkingLifeTextView (gestureRecognizer: UIGestureRecognizer) {

        if gestureRecognizer.state == UIGestureRecognizerState.began {

        self.view.endEditing(true)

       }

   let popController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "IndicativeDesignWorkingLifeVC")

   popController.modalPresentationStyle = UIModalPresentationStyle.popover
                popController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.up

   popController.popoverPresentationController?.delegate = self

   popController.popoverPresentationController?.sourceView = (indicativeDesignWorkingLifeTextView!)

   popController.popoverPresentationController?.sourceRect = (indicativeDesignWorkingLifeTextView as AnyObject).bounds

   self.present(popController, animated: true, completion: nil)

        }

当第二个 View Controller 弹出显示它包含的 UITableView 时。弹出窗口 VIewController 的大小远远大于第二个 View Controller 中设置的表格中包含的行数。

如何将弹出窗口 ViewController 的大小设置为在高度和宽度方面等于第二个 View Controller 中设置的 UITableView 中包含的数据量?

最佳答案

在第 2 个 View Controller 的 viewWillAppear 中,您需要获取 tableView 单元格的行高并计算单元格的数量以获得 tableview 的总高度。完成后,您可以使用 self.preferredContentSize

更改弹出窗口的高度

关于ios - 调整弹出窗口 ViewController 的大小以适应要在 UITableView 中显示的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45764651/

相关文章:

ios - 带有多个内衬标签的 estimatedRowHeight 导致单元格剪裁

ios - defaultNavigationOptions 中的默认背景颜色

java - .rsaEncryptionOAEPSHA256算法在iOS上与Java的兼容性

ios - 如何在 appearance() 中更改 UIButton titlelabel 字体样式和大小?

iphone - 在 iAd 中使用自动布局的问题

ios - 在动态框架中使用 Storyboard

java - 如何删除 JavaFx TableView 行

ios - 来自单个 UIButton 的多个 Segue,该 UIButton 由于 ImageView 而发生变化

ios - 从 MKPolyline 创建 MKMapView 区域

JavaFX TableView 删除问题