Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

popoverContentSize not responding in iOS 8

I Have a piece of code which is as follows: self.popOverController.popoverContentSize = CGSizeMake(248.0, 216.0);

This works fine in iOS 7 and below. However, it doesn't respond to CGSizeMake in iOS 8. No matter what the value is specified with in CGSizeMake(), it takes the same default size.

Please reply with an alternative code.

like image 565
James Lobo Avatar asked Jul 16 '14 05:07

James Lobo


1 Answers

Take two steps to solve this

Step One:

As an immediate fix, you can set preferredContentSize property of UIViewController

[popoverViewController setPreferredContentSize:CGSizeMake(248.0,216.0)]; 

before initalizing UIPopoverController

UIPopoverController *popoverController = [[UIPopoverController alloc]initWithContentViewController:popoverViewController];

Step Two:

In iOS8, UIPopoverPresentationController is getting introduced as a replacement of UIPopoverController

if ([popoverViewController respondsToSelector:@selector(popoverPresentationController)]) {
   popoverViewController.modalPresentationStyle = UIModalPresentationPopover;
   [popoverViewController setPreferredContentSize:CGSizeMake(248.0,216.0)];

   UIPopoverPresentationController *popoverPresentation = popoverViewController.popoverPresentationController;
   [popoverPresentation setSourceView:_sourceView];
   [popoverPresentation setSourceRect:_sourceRect];
   [popoverPresentation setPermittedArrowDirections:UIPopoverArrowDirectionUp];

   [self presentViewController:popoverViewController animated:YES completion:nil];
} else {
   //existing code...
}

As of now, pre-release documentation is available for further reference.

like image 100
ratul Avatar answered Nov 09 '22 11:11

ratul