Programmatically get the storyboard id?

Trying to find out if a UIViewController or UIView can identify its storyboard identifier. So I hoped for:

UIViewController *aViewController; NSString *storyboardID = aViewController.storyboard.id; //not an actual property 

or:

 NSString *storyboardID = [aViewController.storyboard valueForKey:@"storyboardId"]; //also not a working call 

But it was not joyful and could not find a similar solution on the network. Does anyone know if this is possible at all?

+71
ios objective-c xcode identity storyboard
Dec 04
source share
6 answers

You can use restoreIdentifier, this is directly above the Storyboard ID, and this is a property of the UIViewController.

+91
Apr 24 '13 at 17:00
source share

You can use the recovery identifier:

 NSString *restorationId = self.restorationIdentifier; 

Just check the box next to "Use storyboard id"

+57
Apr 22 '14 at 20:27
source share

The storyboard identifier is only for searching and instantiating a VC from the storyboard. As written in the UIStoryboard link:

"This identifier is not a property of the view controller object itself and is used only by the storyboard file to find the view controller.

Why do you need this?

+21
Dec 04
source share

You can also try to do something like this: -

 NSString *storyboardId = [viewController valueForKey:@"storyboardIdentifier"]; 

This will definitely give you the Storyboard Id that you installed through the interface constructor.

Quick expansion:

 extension UIViewController { var storyboardId: String { return value(forKey: "storyboardIdentifier") as? String } } 
+9
Nov 15 '16 at 14:18
source share

The most reliable method for returning the "id" of a UIViewController or UIView is ...

 NSString *viewControllerName = [[NSString alloc] initWithString:viewController.nibName]; 

This will return ... "29w-Ic-LNo-view-FDu-oq-UpZ", where "29w-Ic-LNo" is the identifier of the UIViewController, and "FDu-oq-UpZ" is the identifier of the UIView.

However, you can also use ...

 NSString *viewControllerName = [[NSString alloc] initWithString:viewController.title]; 

This will return the β€œTitle” of the UIViewController in the Attributes Inspector; so it’s as easy as adding a storyboard identifier to a UIViewController, you can also add a title.

+1
Oct 12 '14 at 0:10
source share

You can compare with the class name. import, and then try.

 NSArray *viewControllers = self.navigationController.viewControllers; UIViewController *root = [viewControllers objectAtIndex:0]; if ([root isKindOfClass:[UserLogin class]]) { //--- do --- } 
0
Jun 20 '16 at 9:31
source share



All Articles