[英]How to remove storyboard from existing iPhone project
我是 iPhone 編程的新手,現在面臨故事板的問題。 我想從應用程序中刪除故事板並以編程方式從appDelegate
調用視圖控制器。 我怎樣才能做到這一點?
這是我在appDelegate
代碼:
FirstViewController *firstView = [[FirstViewController alloc] init];
self.window.rootViewController = signInView;
return YES;
仍然顯示黑屏。 請幫我。 謝謝。
刪除主故事板文件基本名稱。 這是.plist。
它顯示黑屏的原因是您的FirstViewController
類中沒有配置任何FirstViewController
。 嘗試設置firstView.view.backgroundColor = [UIColor greenColor];
就在return YES'
之前,您會看到 FirstViewController 實際上正在加載; 除了您在FirstViewController
類的init
方法中所做的之外,它沒有任何配置。
老實說,在 storyboard 之外配置 ViewControllers 對於初學者來說並不好玩。 我不知道您為什么要這樣做,但您的替代方案是使用 .nibs 或手動添加所有內容。 我鼓勵你不要刪除你的故事板,但如果你必須,你的代碼很好。 只需刪除故事板文件,或者更好的是,在您決定返回之前不要使用它,因為這是一個更好的主意。
您是否初始化了窗口並使其成為關鍵?
這是我的一個應用程序的實現:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[DDHDemoViewController alloc] init];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
也許您必須在項目設置中刪除主界面。
以下是我正在做的步驟。
創建一個空項目,或者如果您已經創建了,不用擔心,只需按照@trick 的建議從 plist 中刪除 StoryBoard 條目。
從您的項目中刪除 MainStoryBorad 文件
使用名為“MyViewController”的 XIB 文件創建新的 UIViewController
在您的 AppDelegate.h 中為新控制器“MyViewController”添加 @property
在您的 AppDelegate.m 中以這種方式更新 didFinishLaunchingWithOptions 方法。
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;
MyViewController *viewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}
我認為,如果您的應用程序沒有那么多 UI 視圖控制器那么復雜,那么使用故事板比使用 xib 更好。 如果您想從項目中刪除故事板並使用 nib 與開發一起使用,請執行以下鏈接的步驟:
http://www.wastedpotential.com/create-an-ios-app-without-storyboards-in-xcode-5/
從您的項目中刪除 MainStoryBorad 文件。
從 info.plist 文件中刪除 MainStroryBoard Key。
從項目設置中清除 MainInterface 選項。
使用名為“MyViewController”的 XIB 文件創建新的 UIViewController
在您的 AppDelegate.h 中為新控制器“MyViewController”添加 @property
在您的 AppDelegate.m 中以這種方式更新 didFinishLaunchingWithOptions 方法。
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;
MyViewController *viewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}
請找到以下鏈接並檢查事物.. 1. Info.plist 或 General Info -> 刪除主界面 2. 檢查 .xib 連接 -> 添加自定義類,查看 .xib 中的連接
https://github.com/sunilhts/RemoveDefaultStoryBoard
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.