user6092898
user6092898

Reputation:

Popover menu in landscape occupies the entire screen

Im using the following code to create a popover.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([[segue identifier] isEqualToString:@"popover"]) {
        self.popoverTvc = [segue destinationViewController];
        self.popoverTvc.popoverPresentationController.delegate = self;
    }
}

When the user clicks a button in navigation bar, the above segue of popover style will be triggered and the resulting view controller has got tableview.

The problem is that,

In portrait mode, the size of table view is as per the size of the contents available. But when I change the view from landscape to portrait, the tableview contains empty cells that are visible and hence these empty cells are blocking the ui. Why is that so? I want the tableview not to block the entire screen even in landscape mode.

Im using the following code in view did load method to resize the tableview

if (self.tableView && self.presentingViewController) {
    self.preferredContentSize = [self.tableView sizeThatFits:self.presentingViewController.view.bounds.size];
}

Upvotes: 2

Views: 459

Answers (2)

Zee
Zee

Reputation: 1667

Its been a while, but got the same issue and fixed it by adding both

public func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
    return .none
}

and

public func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
    return .none
}

in the parent / presenting view controller.

Upvotes: 2

TheHungryCub
TheHungryCub

Reputation: 1960

Instead of size of table view is as per the size of the contents available. give the size of popover window programmatically.

Do like follow:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    NSString *identifier = segue.identifier;
    if ([identifier isEqualToString:@"popover"]) {

        UIViewController *dvc = segue.destinationViewController;
        dvc.preferredContentSize = CGSizeMake(180,128);


        UIPopoverPresentationController *ppc = dvc.popoverPresentationController;
        if (ppc) {
            ppc.delegate = self;
        }
    }

And add this below above step:

   - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {

    return UIModalPresentationNone;
}

Upvotes: 0

Related Questions