iOS页面跳转

以FirstViewController(FVC)的按钮button点击后跳转到SecondViewController(SVC)为例。
 
1.StoryBoard 的segues方式
鼠标点击按钮button然后按住control键拖拽到SVC页面,在弹出的segue页面中选择跳转模式。
 
2.导航控制器UINavigationController
  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
  2. {  
  3.     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  
  4.     // Override point for customization after application launch.  
  5.     self.window.backgroundColor = [UIColor whiteColor];  
  6.     RootViewController *root = [[RootViewController alloc]init];  
  7.     UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:root];//先将root添加在navigation上  
  8.     [_window setRootViewController:nav];//navigation加在window上        
  9.     [self.window makeKeyAndVisible];  
  10.     return YES;  
 
  1. - (void)clicked{  
  2.     SecondViewController *second = [[SecondViewController alloc]init];  
  3.     [self.navigationController pushViewController:second animated:YES];  
  4. }  
 
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];
 
 
 
 
 
原文地址:https://www.cnblogs.com/wangqi327/p/5526817.html