How to know the current storyboard name?
17,312
Solution 1
If you are working in a UIViewController class that is instantied or segues through the storyboard the most simple way is :
UIStoryboard *storyBoard = self.storyboard;
If you are in a UIView class that is in a UIViewController
UIResponder *responder = self;
while (![responder isKindOfClass:[UIViewController class]]) {
responder = [responder nextResponder];
if (nil == responder) {
break;
}
}
UIViewController *viewController = (UIViewController *) responder;
UIStoryboard *storyBoard = viewController.storyboard;
Solution 2
Building on Durican's answer above:
Within a view controller:
UIStoryboard * storyboard = self.storyboard;
NSString * storyboardName = [storyboard valueForKey:@"name"];
(The name will not include the ".storyboard" filename extension.)
Author by
wod
Updated on June 19, 2022Comments
-
wod almost 2 years
I want to know what is the current loaded storyboard,I used the below code but it is still get me the Main storyboard not the current.
//This get me the Main storyboard [[NSBundle mainBundle].infoDictionary objectForKey:@"UIMainStoryboardFile"];
-
wod almost 11 yearshow i can get the name ??
-
wod almost 11 yearsmay be you don't understand my question , i want to know the name not set the name of storyboard
-
Shekhar Gupta almost 11 yearsHave you gone through this link: stackoverflow.com/questions/14928817/…
-
VaporwareWolf about 10 yearsPerfect solution. Thanks.
-
VaporwareWolf about 10 yearsQuestion. How did you come up with this? The documentation doesn't say anything about a name property. I don't see a way to query all the keys either. Did you take a stab at it from the IB labels?
-
Xiphias about 10 yearsJust a complete guess, I tested it and it turns out I was right. :)
-
John Estropia over 9 yearsThis is private API so be careful.