Swift presentViewController

后端 未结 13 2097
悲&欢浪女
悲&欢浪女 2020-11-30 21:25

I programatically have multiple View Controllers in an iOS Swift Project. I do not have the storyboards and would like to avoid them if possible. Is there a way to switch to

13条回答
  •  佛祖请我去吃肉
    2020-11-30 21:38

    For reference, because this question is one of the first Google result.

    Breaking change in Swift 3:

    The method presentViewController is replaced by the method present.

    You can use it like the old one:

    self.present(viewControllerToPresent, animated: true, completion: nil)
    

    Example to open the camera:

    let imagePicker = UIImagePickerController()
    imagePicker.delegate = self
    imagePicker.sourceType = UIImagePickerControllerSourceType.camera
    imagePicker.allowsEditing = false
    self.present(imagePicker, animated: true, completion: nil)
    

提交回复
热议问题