控制器跳转方法:
1.用导航栏跳转:a.全自动跳转;b.手动跳转 c.纯代码跳转
全自动跳转:将按钮之间用segue连接下一个控制器。点击按钮会自动进行跳转 使用下面方法传参数; fff是segue的id DSVC是下一个控制器的类型 str 是参数
<span style="font-size:18px;">-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{</span>
<p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: Menlo;"><pre name="code" class="objc"><span style="font-size:18px;">if ([segue.identifier isEqualToString:@"fff"]) {
DSVC *vc = segue.destinationViewController;
vc.str = self.str;
};</span>
<span style="font-size:18px;">}</span>
手动跳转:将控制器和下一个控制器相连,使用下面方法进行跳转 sender 可以传参数 在上面的方法中的sender可以获取 向一个控制器传参方法和上面相同 优点:可以控制跳转时机
<span style="font-size:18px;">self performSegueWithIdentifier:<#(nonnull NSString *)#> sender:<#(nullable id)#></span>
纯代码跳转:传storyboard的名字 控制器的名字 参数在创建控制器后赋值 优点:跳转的控制器可以在新的storyboard中
<span style="font-size:18px;">UIStoryboard *ub = [UIStoryboard storyboardWithName:<#(nonnull NSString *)#> bundle:nil];
DSVC *vc = [[ub instantiateViewControllerWithIdentifier:<#(nonnull NSString *)#>
[self.navigationController pushViewController:vc animated:YES];</span>
2.用UITableBar跳转
//1.创建UITabBar控制器
<span style="font-size:14px;"> </span><span style="font-size:18px;">UITabBarController * tbc = [[UITabBarController alloc] init];
//2.创建被管理的多个控制器
UIViewController * vc1 = [[UIViewController alloc] init];
UIViewController * vc2 = [[UIViewController alloc] init];
UIViewController * vc3 = [[UIViewController alloc] init];
UIViewController * vc4 = [[UIViewController alloc] init];</span>
<span style="font-size:18px;"> //3.设置UITabBarController管理的页面
tbc.viewControllers = @[vc1, vc2, vc3, vc4];</span><span style="font-size:14px;">
</span>
UITabBar的常用属性:tabBarItem.image title selectedImage 设置下的颜色、图片、点击后的状态;
3.根控制器跳转 注意:如果有导航控制器一定要跳转到导航控制器
<span style="font-size:18px;">UIStoryboard *ub = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UINavigationController *vc = [ub instantiateViewControllerWithIdentifier:@"bc"];
self.view.window.rootViewController = vc;</span>