iOS故事板传递数据navigationViewController

发布于 2024-12-20 07:44:58 字数 940 浏览 1 评论 0原文

我在视图之间正确传递数据时遇到问题,但不是以标准方式传递数据。

描述我的问题的图片:

https://i.sstatic.net /0jHYC.png

我使用两个 segue 标识符之一performSegueWithIdentifier,然后我想将数据传递给名为“Firmy”或“Oddzialy”的 ViewController。

传递数据代码:

- (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是NavigationViewController。

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

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

Picture describing my problem:

https://i.sstatic.net/0jHYC.png

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九八野马 2024-12-27 07:44:58

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...
}

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...
}
韬韬不绝 2024-12-27 07:44:58

这是快速的:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) 
{    
    if (segue.identifier == "sLogowanieFirmy") {
        let nav = segue.destinationViewController as! UINavigationController 
        let firmyVC = nav.topViewController as! FirmyVC
        firmyVC.tabFirmy = self.tabFirmy            
    }

    // etc...
}

Here it is in swift:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) 
{    
    if (segue.identifier == "sLogowanieFirmy") {
        let nav = segue.destinationViewController as! UINavigationController 
        let firmyVC = nav.topViewController as! FirmyVC
        firmyVC.tabFirmy = self.tabFirmy            
    }

    // etc...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文