How to get the name of an element of a UIViewControl object from a storyboard

I am trying to define a variable in a property in the UIViewControl class. This variable is a reference for another UIViewControl class called ViewControl.

var handle = ViewControl(nibName: "insert_viewcontroller_id_here", bundle: nil") 

How to get nibName? Also, what is the nib name and why does it need to be referenced when the view control already has the class name UIViewControl?

Best, Alex.

+5
source share
1 answer

If you want to create a new UIViewController, you have two ways to do this.

1st path (programmatic path): create a new class that is a subclass of UIViewController. Thus, you create an instance of the view controller using the following code:

 var viewController = ViewControl() 

2nd way (xib / storyboard path): Create a new viewController using xib or storyboard. So, if you chose this method and you have a view controller created in xib or a storyboard, you must create a new view controller link using the following code:

 //Xib var viewController = UIViewController(nibName: "ViewController", bundle: nil) //Storyboard var viewControllerStoryboardId = "ViewController" var storyboardName = "Main" var storyboard = UIStoryboard(name: storyboardName, bundle: NSBundle.mainBundle()) let viewController = storyboard.instantiateViewControllerWithIdentifier(viewControllerStoryboardId) as UIViewController! 
+2
source

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


All Articles