问题描述
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!