您好,我添加了准备转场代码以传输信息,但是我收到错误。
我有一个标签栏 Controller 。它有 4 个选项卡。每个选项卡都有一个导航 Controller 和一个 VC 作为 Root View Controller 。
从选项卡 1--> 导航 Controller --> VC 1 我需要为选项卡 2--> 导航 Controller ---> VC1 取一个值
(也是连接到选项卡 2 处导航 Controller 的 Segue,或者选项卡 2 处的 Root View ) 预先感谢您
错误:customizedViewControllers]:无法识别的选择器发送到实例 0xf19bd60 (但我要选择选项卡 2(索引 1))? 我的错误在哪里?
if ([segue.identifier isEqualToString:@"ResultsSegue"])
{
//the root VC at tab 2
ResultsIndexViewController*controller=[[ResultsIndexViewController alloc]init];
UITabBarController *tabController = [segue destinationViewController];
controller = (ResultsIndexViewController*)[[tabController customizableViewControllers]objectAtIndex:1];//crashing here
controller.resultsArray=[NSMutableArray arrayWithArray:_matchedResultsArray];
}
}
最佳答案
这部分代码
[1] UITabBarController *tabController = [segue destinationViewController];
[2] controller = (ResultsIndexViewController*)[[tabController customizableViewControllers]objectAtIndex:1];//crashing here
充满了误解。
在[1]中,您将destinationViewController(类型UIViewController
)分配给类型UITabBarController
的对象。这是编译器合法的(UITabBarController
继承自 UIViewController
,因此它们都是 UIViewController
类型),但它并不能真正反射(reflect)正在发生的情况。您的转场将是 UIViewController
或它的 UINavigationController
。
因此,在第 [2] 行中,当您尝试使用 tabController 作为选项卡栏 Controller 时,它会崩溃(因为它不是一个)。
您需要重新设计您的项目...忘记 Segue,并使用选项卡栏 Controller 。类似...
- (IBAction)moveToTab2:(id)sender {
ResultsViewController* resultsVC = (ResultsViewController*)
[[self.tabBarController viewControllers] objectAtIndex:1];
resultsVC.resultsArray=
[NSMutableArray arrayWithArray:_matchedResultsArray];
[self.tabBarController setSelectedViewController:resultsVC;
}
关于ios - 从 View Controller 过渡到选项卡栏 Controller ,并在每个选项卡错误处使用导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14259639/