1、创建工程,删除main.storyboard。同时将设置页面的“General->Development Info->Main Interface”栏中内容清空。
2、创建自己的ViewController和AppDelegate,如下。
3、在AppDelegate.m中修改application:didFinishingLaunchingWithOptions:函数:
#import "AppDelegate.h"
#import "MainViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];//设置窗口
MainViewController *mvc = [[MainViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:mvc];
nav.navigationBarHidden = YES;//是否隐藏导航栏
self.window.rootViewController = nav;//进入的首个页面
[self.window makeKeyAndVisible];//显示
return YES;
}
@end此时进行运行会发现漆黑一片,没有任何东西,其原因是MainViewController的view默认背景色为黑色,故:
4、修改MainViewController.m中的loadView函数:
- (void)loadView
{
[super loadView];
self.view.backgroundColor = [UIColor whiteColor];//将背景设置为白色
}综上,便完成了不使用storyboard的基本开发初始化。
本文详细介绍了如何在iOS应用开发中不使用Storyboard完成基本的工程初始化,包括创建工程、设置页面、实现AppDelegate及ViewController的定制,并解决了运行时出现漆黑屏幕的问题。


被折叠的 条评论
为什么被折叠?



