iOS第一课 设置页面入口
2015-08-06 15:25
543 查看
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];
2.在另一个文件设置入口
(方便合并代码)
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];
使用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];
2.在另一个文件设置入口
(方便合并代码)
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];
相关文章推荐
- iOS des加密
- 用CocoaPods做iOS程序的依赖管理
- iOS开发系列--并行开发其实很容易
- iOS开发系列--打造自己的“美图秀秀”
- iOS开发系列--触摸事件、手势识别、摇晃事件、耳机线控
- iOS 手势添加(代码和storyboard)
- iOS开发系列--视图切换
- ios 开发超实用技巧:Xcode里批量修改 || 工程名 || 变量名 || 修改类名 || 自动封装代码Refactor功能
- iOS 获取本地IP地址
- iOS 顶部高斯模糊导航栏 + 页面内容穿越底部导航栏效果
- iOS开发中讯飞语言的使用
- iOS开发系列--iOS程序开发概览
- 强大的iOS开发必备工具
- 十个好用的 iOS 开发辅助工具与资源
- CocoaPods安装和使用教程
- 关于iOS的GCD的介绍以及使用
- IOS开源库收集整理
- iOS之NSMutableDictionary导致程序崩溃:'NSInternalInconsistencyException'
- ios ViewController 页面跳转
- IOS开发 工具片篇