Tanvir Nayem
Tanvir Nayem

Reputation: 722

Present view controller within details view controller of master details view controller in swift 3

I have some problem to present a view controller within details view controller of master details view controller. Is it possible to do that?

I want to present a view controller when the user taps a button on details view controller exactly like details view controller though it is not.

If it is possible then help me. If not then guide me some way to do that.

Upvotes: 0

Views: 991

Answers (4)

You can try it from Storyboard like,

In the storyboard, select the Segue as present modally, and go to the Identity Inspector, and choose Current Context for the Presentation option.

Hope it helps.

Upvotes: 1

Preeti Rani
Preeti Rani

Reputation: 695

create a static instance of master view controller and then try to present a new view controller with that reference.

class MasterViewController : UIViewController{
static var masterVC : UIViewController?
      override func viewDidLoad() {
        super.viewDidLoad()
       MasterViewController.masterVC = self
      }
}


class DetailViewController : UIViewController{

          override func viewDidLoad() {
            super.viewDidLoad()
          }

          @IBAction func didTapButton(_ sender: UIButton) {
              MasterViewController.masterVC?.present(<newViewController>, animated: true, completion: nil)
          }
}

Upvotes: 0

KKRocks
KKRocks

Reputation: 8322

Try this :

class func presentViewCoontroller(vc : UIViewController) -> Void{
        let viewController : UIViewController = ((UIApplication.shared.delegate as! AppDelegate).window?.rootViewController)!
        if (viewController.presentedViewController != nil)  {
            viewController.presentedViewController?.present(vc, animated: true, completion: nil)
        }
        else{
            viewController.present(vc, animated: true, completion: nil)
        }
    }

Calling

self.presentViewCoontroller(vc: yourcontroller)

Upvotes: 0

Pedro Pinho
Pedro Pinho

Reputation: 662

It's possible, but your details VC must be a navigation Controller, so you can present.

Upvotes: 0

Related Questions