[英]Switching StoryBoards (iphone/iPad) without code?
目前我是這樣做的
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-code決定打開你的info.plist需要哪個故事板加載,並指定哪個故事板應該用於iPad和iphone。
找到具有KEY - 主故事板文件基本名稱的行。
您的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"];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.