Search code examples
iphoneiosstoryboarduistoryboarduistoryboardsegue

How to know the current storyboard name?


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"];

Solution

  • 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;