0

UIViewController has to be presented modally in iPad while the same should be pushed in iPhone. Is there any support for the same by apple by default ?

vivekDas
  • 1,210
  • 8
  • 11
sac
  • 840
  • 5
  • 18

2 Answers2

0

You have to detect the device and perform tasks accordingly.

if UIDevice.current.userInterfaceIdiom == .pad {
    //present modally
} else if UIDevice.current.userInterfaceIdiom == . phone {
    //push
}
Arnab
  • 3,267
  • 1
  • 26
  • 39
0

As already mentioned you will need to do this manually. You can check what device you are having and decide how to present your view controller.

But this usually produces a huge issue and can greatly increase complexity of your application. Since you are in one case presenting and in other case pushing a view controller you will also need to pop or dismiss it. This can easily be solved by adding some extra properties but then later on it might interfere again when you want to dismiss a whole navigation stack or similar. Not to mention problems with deep linking.

So if possible I would try to avoid having different view controller hierarchy depending on device. If possible I would try to simply change the animations (I assume that is all that you need). Maybe this will help.

Matic Oblak
  • 14,391
  • 1
  • 24
  • 37