Create a view controller outside the storyboard

I need a small instructional video in our iOS project, which can be accessed from several controllers (screens). I do not want to break dozens of sections to add this lesson, as this will cause a nightmare. Would there be a better way to do this, by creating a popup view controller that doesn't need to be added to the storyboard? If so, how can I do this?

+4
source share
4 answers

You can use the XIB file without integrating it with the storyboard.

Follow these steps to create a separate XIB (with a Viewcontroller file).

Create a new file: Xcode → Create → File

enter image description here

Select Cocoa Touch Class

enter image description here

XIB

enter image description here

XIB (View Controller):

var viewController = TestViewController(nibName: "TestViewController", bundle: nil)

 // Present
 self.present(viewController, animated: true) {

 }

 //push
 self.navigationController?.pushViewController(viewController, animated: true)

push-. .

+2

.xib.

" ":

enter image description here

:

enter image description here

, nib (xib).

let vc = TutorialViewController(nibName: "TutorialViewController", bundle: nil)
present(vc, animated: true)
+3

View Controller ( "" ) , . , , :

    if let vc = self.storyboard?.instantiateViewController(withIdentifier: "PopUpTutorial") as? PopUpTutorial {
        self.present(vc, animated: true, completion: nil)
    }

"" . :

    let sb = UIStoryboard(name: "Tutorial", bundle: nil)
    if let vc = sb.instantiateViewController(withIdentifier: "PopUpTutorial") as? PopUpTutorial {
        self.present(vc, animated: true, completion: nil)
    }

xib.

0

, :

  • Xcode
  • ""
  • "Cocoa " iOS >
  • " ",
  • "UIViewController"
  • " XIB"
  • "Swift" "Objective c"
  • "".
  • , .
0

Source: https://habr.com/ru/post/1683427/


All Articles