优点:操作方便,无代码生成,在storyboard中展示逻辑清晰
缺点:页面较多时不方便查看,团队合作时可维护性差, 多人合作时不建议使用这种方式。
方式二:选项卡UITabBarController控制器
通过调用UITabBarController的addChildViewController方法添加子控制器,代码实例如下:
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];优点:代码量较少
[self.navigationController pushViewController:newC animated:YES]; //跳转到下一页面在SVC的方法中调用:
[self.navigationController popViewControllerAnimated:YES]; //返回上一页面当有多次跳转发生并希望返回根控制器时,调用:
[ self .navigationController popToRootViewControllerAnimated: YES ]; //返回根控制器,即最开始的页面方式四:利用 Modal 形式展示控制器
[ self presentViewController:SVC animated: YES completion:nil];在SVC中调用:
[ self dismissViewControllerAnimated: YES completion: nil ];方式五:直接更改 UIWindow 的 rootViewController