您的位置:首页 > 移动开发 > IOS开发

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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: