ios13 UIPopoverViewController showing UITableViewController - Safe Area problems / Missing parts of table

前端 未结 3 1597
你的背包
你的背包 2020-12-19 11:20

In the same theme as this post:

iOS 13 - UIPopoverPresentationController sourceview content visible in the arrow

I have a UITableViewController instantiated

相关标签:
3条回答
  • 2020-12-19 12:06

    It seems that you are not using the new Safe Area Layout Guides. The old method is deprecated. If you use storyboard please activate this setting in the File tab:

    In code you can use something like this:

    let guide = view.safeAreaLayoutGuide
    NSLayoutConstraint.activate([
     greenView.topAnchor.constraintEqualToSystemSpacingBelow(guide.topAnchor, multiplier: 1.0),
     guide.bottomAnchor.constraintEqualToSystemSpacingBelow(greenView.bottomAnchor, multiplier: 1.0)
    ])
    

    For more information read this: https://useyourloaf.com/blog/safe-area-layout-guide/

    0 讨论(0)
  • 2020-12-19 12:11

    Okay, so I used up a support ticket with Apple over this - after a year on here with no answers.

    The old way (setting the border on the popover) will never work again because of the under-the-hood auto layout stuff going on with the UITableViewController and it's UITableView.

    The only solution is to remove the UITableViewController completely, and replace it with a UIViewController, with a single view in it, and inside that view, place a UITableView.

    Thankfully the code changes are minimal (just changing the inheritance from UITableViewController to UIViewController, and then add a UITableViewDelegate in)

    Then make sure that the UIViewController containing the table sets itself as the UITableView's delegate and source.

    The longest part of the fix is recreating the layout in Interface Builder, but this time make sure the UITableView doesn't get it's top, leading, bottom, trailing to the SUPERVIEW, but instead to the SAFE AREA.

    Then all you need to do is put this in, and it works:

    override func viewDidLoad()
    {
        super.viewDidLoad()
      
        self.tableView.delegate   = self
        self.tableView.dataSource = self
        
        self.tableView.layer.borderWidth  = 5
        self.tableView.layer.borderColor  = UIColor.white.cgColor
        self.tableView.layer.cornerRadius = 16
    }
    
    0 讨论(0)
  • 2020-12-19 12:12

    I have found the answer. I have to implement my own UIPopoverBackgroundView. Example: https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch09p476popovers/ch22p751popovers/MyPopoverBackgroundView.swift It works for me.my popover

    0 讨论(0)
提交回复
热议问题