How to know the current storyboard name?

前端 未结 3 1770
轻奢々
轻奢々 2020-12-17 15:33

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         


        
相关标签:
3条回答
  • 2020-12-17 15:38

    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;
    
    0 讨论(0)
  • 2020-12-17 15:40

    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];
    
    0 讨论(0)
  • 2020-12-17 15:55

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

    0 讨论(0)
提交回复
热议问题