ios - 无需代码即可切换 StoryBoards (iphone/iPad)?

标签 ios iphone objective-c ipad storyboard

目前我是这样做的

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:
     ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)?
                                @"Main_iPad" : @"Main_iPhone" bundle:nil];

但我很想像 UIImage 那样做:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

然后由 XCode 决定使用后缀查找的位置。

这可能吗?如果是这样怎么办?如果不是,为什么?

最佳答案

那些 _iPad 和 _iPhone 后缀是简单的标识符,可以在您创建新 Storyboard时更改为您喜欢的任何内容,它们与 @2x 内容(或图像 Assets )无关。 但是,如果你大量使用不同的 Storyboard(为了让它们的编辑更简单、更流畅,并且它们的版本控制合并更安全),你可以在 UIStoryboard 上写一个类别,然后用像这样的方法在一个地方写你自己的逻辑

+ (UIStoryboard*) appropriateStoryboardWithName:(NSString*) name bundle:(NSBundle*) bundle             
{
    name = [name stringByAppendingString:
    ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) ? @"_iPad" : @"_iPhone"];
    return [UIStoryboard storyboardWithName:name bundle:bundle];
} 

关于ios - 无需代码即可切换 StoryBoards (iphone/iPad)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22518005/

相关文章:

ios - 如何在 iOS 11 中将导航栏设置为透明

ios - webViewDidFinishLoad() 似乎没有在 Swift 中运行

ios - TableView 的 UIView 无法滚动或点击

iPhone - 扩展 UIImage 以在运行时自定义绘图

javascript - 钛移动开发平台

ios - 无法在标签中显示字典对象值

ios - 如何在 UICollectionView 上添加 UIView 并使用单元格滚动?

ios - 为什么我不能将 true 分配给 Objective-C 中的 BOOL?

ios - 使用 DispatchQueue 索引超出范围异常

iphone - 如何将 JSON 转换为对象