控制器跳转

控制器跳转方法:

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>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值