2
首先,我想強調一下,該代碼正在工作,但看起來很糟糕。我需要以編程方式更改視圖控制器(不能使用segue),所以我使用此代碼:Obj-C以編程方式更改ViewController(兩個故事板)
NSString *storyboardName = @"Main";
UIStoryboard *storyboard =
[UIStoryboard storyboardWithName:storyboardName bundle:nil];
PurchaseViewController *vc = [storyboard
instantiateViewControllerWithIdentifier:@"PurchaseViewController"];
[controller presentViewController:vc animated:YES completion:nil];
Obvoiusly其工作。不幸的是創建後第2個分鏡(新iPad)我是被迫的代碼更改爲:
#define IDIOM UI_USER_INTERFACE_IDIOM()
#define IPAD UIUserInterfaceIdiomPad
/*
...
*/
NSString *storyboardName;
if (IDIOM == IPAD)
storyboardName = @"Main_iPad";
else
storyboardName = @"Main";
UIStoryboard *storyboard =
[UIStoryboard storyboardWithName:storyboardName bundle:nil];
PurchaseViewController *vc = [storyboard
instantiateViewControllerWithIdentifier:@"PurchaseViewController"];
[controller presentViewController:vc animated:YES completion:nil];
它必須比這更好的解決辦法,但我沒有找到一個。你知道替代(更好)的解決方案嗎?