storyboard页面传值及多个storyboard链接

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

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

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  
  2. {  
  3. //    self.selectedIndex = indexPath.row;  
  4. //    [self performSegueWithIdentifier:@"classDetail" sender:nil];  
  5.       
  6. /*---------------------------------第二种传值-----------------------------------------*/  
  7.     LOClassDetailTableViewController *classDeatailVC = [self.storyboard instantiateViewControllerWithIdentifier:@"LOClassDetailTableViewController"];  
  8.     classDeatailVC.loClass = self.loClasses[indexPath.row];  
  9.     [self.navigationController pushViewController:classDeatailVC animated:YES];  
  10.   
  11. /*---------------------------------第一种传值(1)-----------------------------------------*/  
  12.      self.selectedIndex = indexPath.row;  
  13.     [self performSegueWithIdentifier:@"classDetail" sender:self];  
  14. }  
  15.   
  16.   
  17.   
  18. // In a storyboard-based application, you will often want to do a little preparation before navigation  
  19. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender  
  20. {  
  21.     // Get the new view controller using [segue destinationViewController].  
  22.     // Pass the selected object to the new view controller.  
  23.       
  24. /*---------------------------------第一种传值(2)-----------------------------------------*/  
  25.     LOClassDetailTableViewController *classDetailVC = segue.destinationViewController;  
  26.     NSLog(@"---%ld",self.selectedIndex);  
  27.     classDetailVC.loClass = self.loClasses[self.selectedIndex];  
  28. }  


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

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. UINavigationController *deatilNC = [self.storyboard instantiateViewControllerWithIdentifier:@"MDCDeatilBusinessNiewController"];  
  2. //  导航控制器有属性viewControllers,就跟标签控制器一样  
  3. MDCDeatilBusinessViewController *deatilVC = deatilNC.viewControllers[0];  
  4.   
  5. [self presentViewController:deatilNC animated:YES completion:nil];  


[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. 多个storyboard之间沟通只能手写  
  2.   
  3.   
  4. UIStoryboard *secondStoryboard = [UIStoryboard storyboardWithName:@"SecondStoryboard" bundle:nil];  
  5.   
  6. UIViewController *firstVC = [secondStoryboard instantiateViewControllerWithIdentifier:@"firstVC"];  
  7.   
  8. [self.navigationController pushViewController:firstVC animated:YES];  

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

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. //  多个storyboard的衔接  
  2.  if ([[NSUserDefaults standardUserDefaults] boolForKey:@"isAuthenticated"] == NO) {  
  3.        
  4.      UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];  
  5.      UIViewController *viewController = [mainStoryboard instantiateInitialViewController];  
  6.      [UIApplication sharedApplication].keyWindow.rootViewController = viewController;  
  7.  }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值