iOS页面跳转
以FirstViewController(FVC)的按钮button点击后跳转到SecondViewController(SVC)为例。
1.StoryBoard 的segues方式
鼠标点击按钮button然后按住control键拖拽到SVC页面,在弹出的segue页面中选择跳转模式。
2.导航控制器UINavigationController
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- // Override point for customization after application launch.
- self.window.backgroundColor = [UIColor whiteColor];
- RootViewController *root = [[RootViewController alloc]init];
- UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:root];//先将root添加在navigation上
- [_window setRootViewController:nav];//navigation加在window上
- [self.window makeKeyAndVisible];
- return YES;
- }
- - (void)clicked{
- SecondViewController *second = [[SecondViewController alloc]init];
- [self.navigationController pushViewController:second animated:YES];
- }
3.选项卡UITabbarController
通过调用UITabBarController的addChildViewController方法添加子控制器,代码实例如下:
1
2
3
4
5
6
7
8
9
10
|
UITabBarController *tabbarVC = [[ UITabBarController alloc ] init ]; FirstViewController *FVC = [[FirstViewController ] init ]; FVC.tabBarItem.title = @ "控制器1" ; FVC.tabBarItem.image = [ UIImage imageNamed : @ "first.png" ]; SecondViewController *SVC = [[SecondViewController ] init ]; SVC.tabBarItem.title = @ "控制器2" ; SVC. tabBarItem.image = [UIImage imageNamed : @ "new.png" ]; // 添加子控制器(这些子控制器会自动添加到UITabBarController的 viewControllers 数组中) [tabbarVC addChildViewController :FVC]; [tabbarVC addChildViewController :SVC]; |
posted on 2016-05-25 14:13 DayDayUp~~ 阅读(110) 评论(0) 编辑 收藏 举报