Ios 无代码切换故事板(iphone/iPad)?
目前我是这样做的Ios 无代码切换故事板(iphone/iPad)?,ios,iphone,objective-c,ipad,storyboard,Ios,Iphone,Objective C,Ipad,Storyboard,目前我是这样做的 UIStoryboard *storyboard = [UIStoryboard storyboardWithName: ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)? @"Main_iPad" : @"Main_iPhone" bundle:nil]; 但我很想像UIImage那样做: UIStor
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后缀是简单的标识符,当你创建一个新的故事板时,它们可以在任何你喜欢的地方更改,并且它们与@2x内容(或者图像资产)无关。 但是,如果您大量使用不同的故事板(以使它们的编辑更简单、更流畅、版本控制更安全地合并),您可以在UIStoryboard上编写一个类别,并使用以下方法在一个位置编写自己的逻辑:
+ (UIStoryboard*) appropriateStoryboardWithName:(NSString*) name bundle:(NSBundle*) bundle
{
name = [name stringByAppendingString:
([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) ? @"_iPad" : @"_iPhone"];
return [UIStoryboard storyboardWithName:name bundle:bundle];
}
如果您想让x代码决定打开info.plist和 指定iPad和iphone应使用的情节提要 查找具有键-主情节提要文件基名称的行 您的info.plist必须有这两行
KEY TYPE VALUE
Main storyboard file base name (iPad) String Main_iPad
Main storyboard file base name (iPhone) String Main_iPhone
现在,每次你的应用程序启动时,x-code都会决定哪个故事板加载不带代码
希望能有帮助
祝你好运 而不是编写所有代码:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:
([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)?
@"Main_iPad" : @"Main_iPhone" bundle:nil];
如果调用self.storyboard
,Xcode可以加载正确的故事板
因此,您可以直接使用它,例如:
someViewController *pieVC = [self.storyboard
instantiateViewControllerWithIdentifier:@"someView"];
如果您只使用一个故事板(每个形状因子),您可以在Info.plist中设置它。在项目文件中选择你的应用程序,在目标中选择你的应用程序,选择“常规”选项卡,在“部署信息”下,你可以通过切换“设备”弹出窗口来更改主界面。@David我不理解你的建议,我有两个故事板,我不想进行检查。我希望xCode像查找
@2x.png
AFAIK一样查找后缀,您可以将后缀~ipad
和~iphone
用于nib文件名,但不能用于故事板。我不认为有什么好的理由可以忽略这一点。从一个通用项目开始。然后相应的故事板将自动加载。这是一个通用的应用程序,我使用这行代码来显示视图,所以基本上我想要实现的是不可能的,对吗?