How to know the current storyboard name?

心已入冬 提交于 2019-11-29 05:51:36

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;

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

Just do this, this may solve your query

NSString *storyboardName;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    storyboardName = @"iPad";
} else {
    storyboardName = @"iPhone";
}
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!