常见的页面跳转的方法

来源:互联网 发布:php 页面重定向方法 编辑:程序博客网 时间:2024/05/19 14:51

1.//方法一presentViewController;用这种方法来推到下一个页面,有时候还需要返回到上一个页面的时候,就需要额外实现一个方法 ,与 presentViewController: 对应的返回方法为dismissViewControllerAnimated: 在第二个页面添加一个button 对其添加一个方法,方法的实现里面加上这一行代码就可以了
例如 [self presentViewController:detail animated:YES completion:nil];
//self.window.rootViewController=[[ViewController alloc]init];
2.//方法二UINavigation要求使用导航框架;UINavigationController相当于是一个容器,然后将所有的view都放到这个容器里面去
例如:[self.navigationController pushViewController:detail animated:YES];//返回代码popViewControllerAnimated
//在appdelegate中代码如下
//ViewController *view=[[ViewController alloc]init];
//UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:view];
//self.window.rootViewController=nav;

3.//方法三UITabBarController
UITabBarController *tab=[[UITabBarController alloc]init];//a.初始化一个tabBar控制器
self.window.rootViewController=tab;
UIViewController *c1=[[UIViewController alloc]init];
//c1.view.backgroundColor=[UIColor grayColor];
c1.tabBarItem.title=@”123”;

UIViewController *c2=[[UIViewController alloc]init];
//c2.view.backgroundColor=[UIColor brownColor];
c2.tabBarItem.title=@”456”;

//c.添加子控制器到ITabBarController中
//c.1第一种方式
// [tab addChildViewController:c1];
// [tab addChildViewController:c2];

//c.2第二种方式
tab.viewControllers=@[c1,c2];

4.将其他页面直接加到当前页面
[html] view plain copy
在CODE上查看代码片派生到我的代码片

view1=[[view21 alloc]initWithNibName:@"view21" bundle:nil];      [mainScr addSubview:view1.view];      view1.view.frame=CGRectMake(0, 0, 1024, 768);  

其对应的返回到前一个页面的方法可以使用

[view1 removeFromSuper];  

第四种:

introView = [[CompanyIntroViewController alloc]init];

[self.view insertSubview:introView.view aboveSubview:backImageView];

0 0