如何知道当前的故事板名称?

我想知道当前加载的故事板是什么,我使用了下面的代码,但它仍然让我的主要故事板不是目前。

//This get me the Main storyboard [[NSBundle mainBundle].infoDictionary objectForKey:@"UIMainStoryboardFile"]; 

如果你在一个UIViewController类中工作,这个类是通过故事板实现的,那么最简单的方法是:

 UIStoryboard *storyBoard = self.storyboard; 

如果你在一个UIViewController中的UIView类

 UIResponder *responder = self; while (![responder isKindOfClass:[UIViewController class]]) { responder = [responder nextResponder]; if (nil == responder) { break; } } UIViewController *viewController = (UIViewController *) responder; UIStoryboard *storyBoard = viewController.storyboard; 

基于上面的Durican的回答:

在视图控制器中:

 UIStoryboard * storyboard = self.storyboard; NSString * storyboardName = [storyboard valueForKey:@"name"]; 

(名称不包含“.storyboard”文件扩展名。)

只要这样做,这可能会解决您的查询

 NSString *storyboardName; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { storyboardName = @"iPad"; } else { storyboardName = @"iPhone"; } UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];