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.)

Share:
17,312
wod
Author by

wod

Updated on June 19, 2022

Comments

  • wod
    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
    wod almost 11 years
    how i can get the name ??
  • wod
    wod almost 11 years
    may be you don't understand my question , i want to know the name not set the name of storyboard
  • Shekhar Gupta
    Shekhar Gupta almost 11 years
    Have you gone through this link: stackoverflow.com/questions/14928817/…
  • VaporwareWolf
    VaporwareWolf about 10 years
    Perfect solution. Thanks.
  • VaporwareWolf
    VaporwareWolf about 10 years
    Question. 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
    Xiphias about 10 years
    Just a complete guess, I tested it and it turns out I was right. :)
  • John Estropia
    John Estropia over 9 years
    This is private API so be careful.