0

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.

Sanjay Shah
  • 502
  • 2
  • 13
Tanvir Nayem
  • 702
  • 10
  • 25

4 Answers4

1

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.

  • This should be the accepted answer. Also if you're presenting programatically, do: viewController.modalPresentationStyle = .overCurrentContext – SN81 Sep 20 '19 at 11:59
0

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

Pedro Pinho
  • 652
  • 3
  • 6
0

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)
KKRocks
  • 8,222
  • 1
  • 18
  • 84
  • I dont want to view the viewController within the whole screen. I just want to view the viewController within the details view controller. When i tap on a button then this event should occurs. – Tanvir Nayem Jul 18 '17 at 02:32
0

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)
          }
}
Preeti Rani
  • 685
  • 7
  • 17
  • your code is presenting the view controller within full screen.But I don't want that. I want to present the newViewController only within details view controller screen. That time i also want to see my master table view controller in my screen. – Tanvir Nayem Jul 17 '17 at 17:15
  • can you share your view (master controller ) related to this code – Preeti Rani Jul 18 '17 at 11:06