Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Monday, June 20, 2016

Programmatically get a Storyboard ID?

Programmatically get a Storyboard ID?


Trying to see if a UIViewController or UIView can identify it's Storyboard ID. So was hoping 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 no joy and couldn't find a similar solution online. Does anyone know if this is even possible?

Answer by LombaX for Programmatically get a Storyboard ID?


The storyboard id is only meant to find and instantiate a VC from a storyboard. As written in the UIStoryboard reference:

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

Why do you need it?

Answer by Lolloz89 for Programmatically get a Storyboard ID?


You can use the restorationIdentifier, it's right above the Storyboard identifier and it's a UIViewController property.

Answer by Erickson1 for Programmatically get a Storyboard ID?


You can use the Restoration ID:

NSString *restorationId = self.restorationIdentifier;  

Just check the checkbox 'Use Storyboard ID'

Answer by serge-k for Programmatically get a Storyboard ID?


The most reliable method for returning the "id" of the 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 Object ID of the UIViewController and "FDu-oq-UpZ" is the Object ID of the UIView.

However, you may also use...

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

This will return the "Title" of the UIViewController in the Attributes Inspector; so just as easily as you added the Storyboard ID to the UIViewController, you may also add a title.

Answer by Deepak Kumar Sahu for Programmatically get a Storyboard ID?


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

NSArray *viewControllers = self.navigationController.viewControllers;  UIViewController *root = [viewControllers objectAtIndex:0];  if ([root isKindOfClass:[UserLogin class]]) {  //--- do ---  }  


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.