iOS第一课 设置页面入口
使用xib文件,删除storyboard,在工程中将main interface设置为空
1.直接在AppDelegate文件中
DefaultVC *defaultVC = [[DefaultVCalloc]init];
_window = [[UIWindowalloc]initWithFrame:CGRectMake(0,0, [[UIScreenmainScreen]bounds].size.width, [[UIScreenmainScreen]bounds].size.height)];//创建win
或者
_window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
_window.rootViewController = defaultVC; //设置入口
[_windowmakeKeyAndVisible];
DefaultVC *defaultVC = [[DefaultVCalloc]init];
AppDelegate *appDelegate = [[UIApplicationsharedApplication]delegate];
appDelegate.window = [[UIWindowalloc]initWithFrame:CGRectMake(0,0, [[UIScreenmainScreen]bounds].size.width, [[UIScreenmainScreen]bounds].size.height)];
appDelegate.window.rootViewController = defaultVC;
[appDelegate.windowmakeKeyAndVisible];
或者
_window = [[UIWindowalloc]initWithFrame:CGRectMake(0,0, [[UIScreenmainScreen]bounds].size.width, [[UIScreenmainScreen]bounds].size.height)];创建win写在AppDelegate文件,另一个文件中写
+ (void) center{
DefaultVC *defaultVC = [[DefaultVCalloc]init];
AppDelegate *appDelegate = [[UIApplicationsharedApplication]delegate];
UIWindow *window = appDelegate.window;
window.rootViewController = defaultVC;
[window makeKeyAndVisible];
}
类方法实现加入添加导航栏代码,以1为例变换,注意红色
DefaultVC *defaultVC = [[DefaultVC alloc]init];
UINavigationController *defaultNavC = [[UINavigationController alloc]initWithRootViewController:defaultVC];
_window = [[UIWindow alloc]initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen]bounds].size.width, [[UIScreenmainScreen]bounds].size.height)];//创建win
_window.rootViewController =defaultNavC; //设置入口
[_window makeKeyAndVisible];
但是首页不需要显示导航栏,隐藏导航栏
[self.navigationController.navigationBarsetHidden:YES];