storyboard页面传值及多个storyboard链接

@在之前的几篇文章,已经介绍了storyboard页面之间的跳转和传值,对于那几种传值方法,其实与纯代码构建的页面传值是一个道理,都是可以用属性,代理,通知,block,单例等方法传值(具体可见iOS高级),storyboard只是帮我们简化了构建view的代码,整体的原理还是一样的,主要是获得跳转的那个ViewController对象即可,下面,我就给出种方式的关键代码:

      2种的ID不一样,一种是中间连线那个圈圈里面的Identifier,一种是跳转页面的Storyboard ID

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    self.selectedIndex = indexPath.row;
//    [self performSegueWithIdentifier:@"classDetail" sender:nil];
    
/*---------------------------------第二种传值-----------------------------------------*/
    LOClassDetailTableViewController *classDeatailVC = [self.storyboard instantiateViewControllerWithIdentifier:@"LOClassDetailTableViewController"];
    classDeatailVC.loClass = self.loClasses[indexPath.row];
    [self.navigationController pushViewController:classDeatailVC animated:YES];

/*---------------------------------第一种传值(1)-----------------------------------------*/
     self.selectedIndex = indexPath.row;
    [self performSegueWithIdentifier:@"classDetail" sender:self];
}



// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    
/*---------------------------------第一种传值(2)-----------------------------------------*/
    LOClassDetailTableViewController *classDetailVC = segue.destinationViewController;
    NSLog(@"---%ld",self.selectedIndex);
    classDetailVC.loClass = self.loClasses[self.selectedIndex];
}


     一个没有导航栏(有的直接push想要那个viewController就行,会统一自带)的viewController模态推出一个在storyboard中拖入的UINavigationController,如何找到导航控制器下的viewController,给予UINavigationController的storyboardID就行

        UINavigationController *deatilNC = [self.storyboard instantiateViewControllerWithIdentifier:@"MDCDeatilBusinessNiewController"];
        //  导航控制器有属性viewControllers,就跟标签控制器一样
        MDCDeatilBusinessViewController *deatilVC = deatilNC.viewControllers[0];
    
        [self presentViewController:deatilNC animated:YES completion:nil];


多个storyboard之间沟通只能手写


UIStoryboard *secondStoryboard = [UIStoryboard storyboardWithName:@"SecondStoryboard" bundle:nil];

UIViewController *firstVC = [secondStoryboard instantiateViewControllerWithIdentifier:@"firstVC"];

[self.navigationController pushViewController:firstVC animated:YES];

@QQ的登录,注册,找回密码用一个storyboard;登录成功后的主界面的链接用一个storyboard

   //  多个storyboard的衔接
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"isAuthenticated"] == NO) {
        
        UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UIViewController *viewController = [mainStoryboard instantiateInitialViewController];
        [UIApplication sharedApplication].keyWindow.rootViewController = viewController;
    }


  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值