3

I want to make a behavior like contacts app in iPad with landscape mode.

I'm expecting that a Modal shows in a Detail view when I click upper right add button.

but now if I click upper right add button, the Modal shows in all screen.

what method should I use? showDetailViewController? or presentViewController? I don’t know how to show Modal in only Detail View.

Yaz
  • 492
  • 1
  • 6
  • 20
user2526811
  • 1,233
  • 4
  • 20
  • 54

1 Answers1

4

Firstly you need to set detail view controller's property definesPresentationContext = true. So now it defines presentation context. By default view controllers doesn't pay attention to the current context when they are presented therefore you must do viewController.modalPresentationStyle = .CurrentContext

That's how complete method looks like

func adaptivePresentViewController(viewController: UIViewController) {
  let detailVC = splitViewController!.viewControllers[1]
  detailVC.definesPresentationContext = true
  viewController.modalPresentationStyle = .CurrentContext
  detailVC.presentViewController(viewController, animated: true, completion: nil)
}
Artur
  • 41
  • 1
  • 3