简体   繁体   中英

How to use presentModalViewController in iPad

I have created a Cartview and want to display this view as a modalview when i click a button on productview.How can i do this ? Actually i did this like

 UIViewController *nav=[[UIViewController alloc]initWithNibName:@"CartView-iPad"    bundle:nil];
    nav.modalPresentationStyle=UIModalPresentationFormSheet;
    nav.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:nav animated:YES];
    CGRect frame=nav.view.frame;
    frame.origin.x -= 75;
    frame.origin.y = 100;
    nav.view.frame=CGRectMake(frame.origin.x,  frame.origin.y , 672, 393);

But the problem is the formsheet view is coming and my cart view is coming overt that i need only my cartview.Also i need a close button on the right to side of the cartview to dissmiss the modalview.

The problem may be that you're trying to set the frame of the modal view controller manually. This is, as far as I know, not recommended. The UIModalPresentationFormSheet option already indicates the desired size of the modal.

As for a back button, you should add a navigation bar with a back button in your CartView-iPad -xib-file. To make it work you have to make a subclass of UIViewController (example: CartViewController ) which will handle the back button press. Right now nav is just a normal UIViewController which has no idea what to do with the actions in your xib-file.

Then in your new view controller, you can make a function like this that you connect your back button to:

- (IBAction)backButtonPressed
{
   [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM