Modal controller as a Popover on iPad

On iPads the modal controllers can be presented as a popover views. Here's how you can do it. There are some tricky problems which the following code removes, such as, the popover view shows white rounded corners which are undisrable (more discussed here):

 

 

     PopoverVC *ctrl = [[PopoverVC alloc] initWithNibName:@"PopoverVC" bundle:nil];

     
// Create a Navigation controller
     
UINavigationController *navController = [[UINavigationController alloc]
                                                         initWithRootViewController
:ctrl];

     
[self.navigationController pushViewController:ctrl animated:YES];
     navController
.modalPresentationStyle = UIModalPresentationFormSheet;
     navController
.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
     navController
.view.backgroundColor = [UIColor clearColor];        

     
// show the navigation controller modally
     
[self presentModalViewController:navController animated:YES];
      navController
.view.superview.frame = CGRectMake (200,200,400,400);
     
// Following removes the white round edges from the corner.       <<<<<<<<-------------  
     navController
.view.superview.layer.cornerRadius = 8;
     navController
.view.superview.layer.borderColor = [UIColor clearColor].CGColor;
     navController
.view.superview.layer.borderWidth = 2;
     navController
.view.superview.clipsToBounds = YES;
 
[navController release];
     
[ctrl release];


For the PopoverVC

 

- (void)viewDidLoad

{

[super viewDidLoad];

// Do any additional setup after loading the view from its nib.

self.navigationController.navigationBarHidden = YES;

}

 

Partners

Pioneer-Electronics-Logo

 

Texas-Instruments-logo

 

Zypr

GammaPoint Tweets

Navigation