Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the nib Name of a UIViewControl object from the storyboard

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

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

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

Best, Alex.

like image 390
Alexander Soare Avatar asked Dec 24 '14 12:12

Alexander Soare


1 Answers

If you want to create a new UIViewController you have two ways of doing this.

1st way (programmatically way) : Create a new class that is subclass of UIViewController. In this way, you instantiate a view controller using follow code:

var viewController = SomeViewController()

2nd way (xib/storyboard way) : Create new ViewController using xib or storyboard. So if you choice this way and you have a view controller created in xib or storyboard you should create a new reference of view controller using follow 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!
like image 54
tikhop Avatar answered Oct 12 '22 16:10

tikhop