Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Present Modal View in Detail View in UISplitViewController

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.

like image 622
user2526811 Avatar asked Jan 20 '26 10:01

user2526811


1 Answers

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)
}
like image 177
Artur Avatar answered Jan 23 '26 04:01

Artur



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!