0

I want to display a view controller inside a view controller. I'm using popup segue to do this. Second view controllers settings are like below and but It shows in fullscreen anyway.

 func tappedView3() {
    // get a reference to the view controller for the popover
    let popController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "popoverId")

    // set the presentation style
    popController.modalPresentationStyle = UIModalPresentationStyle.popover

    // set up the popover presentation controller
    popController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.up
    popController.popoverPresentationController?.delegate = self
    popController.popoverPresentationController?.sourceView = m_tumgun // button
    popController.popoverPresentationController?.sourceRect = m_tumgun.bounds

    // present the popover
    self.present(popController, animated: true, completion: nil)
}

// UIPopoverPresentationControllerDelegate method
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
    // Force popover style
    return UIModalPresentationStyle.none
}

enter image description here

Emre Önder
  • 2,408
  • 2
  • 23
  • 73

2 Answers2

0

You should use Container View for this.

enter image description here

enter image description here

Read more here: https://developer.apple.com/library/content/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html

Vlad Khambir
  • 4,313
  • 1
  • 17
  • 25
  • I red about containerview but my problem is that I'm opening second view via a button and that button disappears when new container view opened. As I searched, for example that button should be still in view. – Emre Önder Jul 18 '17 at 12:33
  • @EmreÖnder, Container View is just view. You can add it as a subview of your main view controller. – Vlad Khambir Jul 18 '17 at 12:44
0
class TablePopupController: UIViewController {
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
    super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    self.modalPresentationStyle = .overCurrentContext
    self.modalTransitionStyle = .crossDissolve
}
required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}
/// to touch button which pressed
///
/// - Parameter sender: button presse
@IBAction func toDismissView(_ sender: AnyObject) {
    self.handler!(nil)
    self.dismiss(animated: true, completion: nil)
}

you can use it in other controller by following line

let lifeStyleTablePopup = TablePopupController(nibName: NibName.TablePopupController.rawValue, bundle: nil)
self.present(self.lifeStyleTablePopup, animated: true, completion: {
})

I hope this will helps you

Prabhjot Singh Gogana
  • 1,408
  • 1
  • 14
  • 39