Search code examples
iosobjective-cxcode7uipopovercontroller

show one view controller on other view controller as a subview(popoverController)


hello i want to present a controller on a main view Controller with popover functionality can anyone me out this ?? i have already tried this below code but it is comin on all view, i want it in small size at the center of view. here is the code below

Login *popoverController = [[Login alloc] init];
popoverController.popoverPresentationController.sourceView = self.view; //The view containing the anchor rectangle for the popover.
popoverController.popoverPresentationController.sourceRect = CGRectMake(384, 40, 40, 40); //The rectangle in the specified view in which to anchor the popover.
[self presentViewController:popoverController animated:YES completion:nil];

Solution

  • You can use Container View. Add a container view to your parent view and add other view controllers in your container view.

     self.addChildViewController(vc)
    vc.view.frame = CGRectMake(0, 0, self.container.frame.size.width, self.container.frame.size.height);
    self.container.addSubview(vc.view)
    vc.didMoveToParentViewController(self)