Is it possible to programmatically get the identifier of a basic UIViewController from an UIViewController or Storyboard in Swift/Objective-C?
In Swift:
var str: String! = self.restorationIdentifier
programmatically access UIViewController identifier
This question solves my problem for me:
Programmatically get a Storyboard ID?
I am just using the restorationId instead, works perfectly.
Programmatically get a Storyboard ID?
You can use the restorationIdentifier, it's right above the Storyboard identifier and it's a UIViewController property.
Instantiate and Present a viewController in Swift
This answer was last revised for Swift 5.4 and iOS 14.5 SDK.
It's all a matter of new syntax and slightly revised APIs. The underlying functionality of UIKit hasn't changed. This is true for a vast majority of iOS SDK frameworks.
let storyboard = UIStoryboard(name: "myStoryboardName", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "myVCID")
self.present(vc, animated: true)
Make sure to set myVCID
inside the storyboard, under "Storyboard ID."
How do I give an identifier to a view controller within my storyboard?
As the Image suggests! Hope it helps!
Then to use it you call:
[self.storyboard instantiateViewControllerWithIdentifier:@"YourViewControllerID"];
How to load UIViewController programmatically from storyboard?
The way you're doing this just creates a new instance of your view controller. It does not create one from the prototype you've defined in Interface Builder. Instead, you should be using this, where "SomeID" is a storyboard ID that you've assigned to your view controller in Interface Builder.
if let resultController = storyboard!.instantiateViewControllerWithIdentifier("SomeID") as? ResultViewController {
presentViewController(resultController, animated: true, completion: nil)
}
You can assign a storyboard ID to your view controller in Interface Builder's identity inspector.
iOS how to get a reference to a view controller embedded in a storyboard container with a segue?
you must implement the prepareForSegue in main ViewController and specify an identifier in your StoryBoard.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:@"YOUR_SEGUE_NAME_HERE"])
{
// Get reference to the destination view controller
YourViewController *vc = [segue destinationViewController];
}
}
Related Topics
Swift: Protocol VS. Struct VS. Class
Exc_Bad_Access Using Ibinspectable
Programmatically Set Uipageviewcontroller Transition Style to Scroll
Errortype' Is Not Convertible to 'Nserror'
When Should I Use Anyobject Insted of Uibutton in Swift
Cannot Invoke Initializer for Type Unsafemutablepointer<Uint8>
Mpmovieplayercontroller Stops Playing After 5 Seconds - Swift
Most Efficient/Realtime Way to Get Pixel Values from iOS Camera Feed in Swift
Multiple Iboutlets in Same Line of Same Type in Swift
Finding It Difficult to Pass Data to Separate Viewcontroller
Alamofireimage Disk Cache Not Working
Cropping Avasset Video with Avfoundation Not Working iOS 8
How to Create Gmsmarker with Combined Images in Swift
How to Delete an Image from Photolibrary After I Pick It Up Using Uiimagepickercontroller