IOS界面之间跳转的几种方式
下面就以点击 FirstController
的 button 按钮跳转到SecondController
为例进行介绍:
方式一:StoryBoard 的segues 方式
鼠标右击按钮button然后按住 control 键拖拽到 SecondController页面中选择跳转模式即可
![](https://img.haomeiwen.com/i2887690/1def8fc443c3c2f2.png)
优点:操作简单,无代码生成
缺点:页面较多时查看不方便,可维护性查
方式二:UITabBarController 控制器
UITabBarController *tabVc=[[UITabBarController alloc] init];
FirstController *firstVc=[[FirstController alloc] init];
firstVc.tabBarItem=@"控制器1";
SecondController *secondVc=[[SecondController alloc] init];
secondVc.tabBarItem=@"控制器2";
[tabVc addChildViewController:firstVc];
[tabVc addChildViewController:secondVc];
方式三:UINavigationController 导航控制器
在FirstController的按钮监听方法中调用:
[self.navigationController pushViewController:first animated:YES];// 跳转到下一页
在SecondController中调用:
[self.navigationController popViewControllerAnimated:YES];// 返回上一界面
当有多次跳转发生并希望放回根控制器时,调用:
[self presentViewController:second animated:YES completion:nil];
方式四:利用 Modal 形式展示控制器
在FirstController中调用:
[self presentViewController:second animated:YES completion:nil];
在SecondController中调用:
[self dismissViewControllerAnimated:YES completion:nil];
网友评论