2
votes

Using Xcode 10.1 and Swift 4.2.1, iOS 12

I got a tableview embedded in a navigation controller. In the upper right corner a bar button and a segue (popover) from this button to a navigation controller which holds a static table view, here the cells has further segues to other table views.

On an iPhone the static table view is displayed as a full screen modal, on an iPad it's a popover, which is okay so far. I've set everything up in the storyboard, don't know if this could be the reason, but now I'm struggling to check if the view is a popover or a full screen modal.

I've tried:

print("\(presentationController)")
if presentationController is UIPopoverPresentationController {
    // Do something
}

But this doesn't work -> print("\(presentationController)") gives me Optional(<_UIFullscreenPresentationController: 0x7fd00ad45770>) on iPhone and iPad.

I've tried also with:

if popoverPresentationController != nil {
    print("popover")
}

But popover is printed if launched on iPhone or iPad.

Am I doing something wrong here or am I missing something?

2
@RajSharma I've read that one already. The initial question was written over 3 1/2 years ago, iOS8. The officially marked answer is just a small description without any code, which I tried by the way but wasn't able to come along with. Also other answers I've found are even older and in objective c (never used/written objective c before). So I would guess in iOS 12 are "some" changes and updates compared to iOS8, which maybe makes it easier to check if in a popover. - Leo
@Leo, Does the below answer solves this issue? - Anand

2 Answers

1
votes

Currently I'm using this:

if (popoverPresentationController?.arrowDirection != UIPopoverArrowDirection.unknown) {
    tableView.sectionHeaderHeight = CGFloat.leastNormalMagnitude
    tableView.sectionFooterHeight = CGFloat.leastNormalMagnitude
}

It's easy, and it works. In case someone has a real possibility to find out "if is a popover", you are very welcome to post it in here.

-1
votes

Use "UIModalPresentationStyle" of the presentedViewController to detect presentation style is fullscreen or popover.

You can find more details here: https://developer.apple.com/documentation/uikit/uimodalpresentationstyle