iOS storyboard传递数据navigationViewController [英] iOS storyboard passing data navigationViewController

查看:153
本文介绍了iOS storyboard传递数据navigationViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

strong>





performSegueWithIdentifier 与两个segue标识符之一,然后在我想传递数据到ViewController称为稳定或Oddzialy。



传递数据代码:

   - (void)prepareForSegue: UIStoryboardSegue *)segue sender:(id)sender 
{
if([[segue identifier] isEqualToString:@sLogowanieFirmy]){
FirmyVC * firmyVC = [segue destinationViewController];
firmyVC.tabFirmy = self.tabFirmy;
}
if([[segue identifier] isEqualToString:@sLogowanieOddzialy]){
OddzialyVC * oddzialyVC = [segue destinationViewController];
oddzialyVC.wybranaFirma = [self.tabFirmy objectAtIndex:0];
}
}

问题是使用方法 [segue destinationViewController] segue destinationViewController for segue是NavigationViewController。



那么什么是传递数据和具有独立导航控制器的正确方法?

解决方案

UINavigationController 有一个名为 topViewController 的属性,返回位于堆栈顶部的视图控制器。



因此,您的 prepareForSegue:方法可能如下所示:

   - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{
if [[segue identifier] isEqualToString: @sLogowanieFirmy]){
UINavigationController * nav = [segue destinationViewController];
FirmyVC * firmyVC =(FirmyVC *)nav.topViewController;
firmyVC.tabFirmy = self.tabFirmy;
}

// etc ...
}


I have problem with proper passing data between view's but not in standard way.

Picture describing my problem:

I performSegueWithIdentifier with one of two segue identifiers and then in I want to pass data to ViewController called "Firmy" or "Oddzialy".

Passing data code:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
  if ([[segue identifier] isEqualToString:@"sLogowanieFirmy"]) {
      FirmyVC *firmyVC = [segue destinationViewController];
      firmyVC.tabFirmy = self.tabFirmy;
  }
  if ([[segue identifier] isEqualToString:@"sLogowanieOddzialy"]) {
      OddzialyVC *oddzialyVC = [segue destinationViewController];
      oddzialyVC.wybranaFirma = [self.tabFirmy objectAtIndex:0];
  }
}

Problem is with method [segue destinationViewController] becouse destinationViewController for segue is NavigationViewController.

So what is proper way to pass data and have independent Navigation Controllers?

解决方案

UINavigationController has a property called topViewController which returns the view controller that is at the top of the stack.

So your prepareForSegue: method may look something like this...

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"sLogowanieFirmy"]) {
        UINavigationController *nav = [segue destinationViewController];
        FirmyVC *firmyVC = (FirmyVC *)nav.topViewController;
        firmyVC.tabFirmy = self.tabFirmy;
    }

    // etc...
}

这篇关于iOS storyboard传递数据navigationViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆