您好我为segue代码添加了准备以传输信息,但是我收到了错误。
我有一个标签栏控制器。它有4个标签。每个选项卡都有一个导航控制器,一个VC作为根视图控制器。
来自标签1 - >导航控制器 - > VC 1我需要取值到tab2 - >导航控制器---> VC1
(也是在选项卡2处连接到导航控制器的segue,或选项卡2处的根视图) 提前谢谢
错误:customizableViewControllers]:无法识别的选择器发送到实例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];
}
}
答案 0 :(得分:1)
这部分代码
[1] UITabBarController *tabController = [segue destinationViewController];
[2] controller = (ResultsIndexViewController*)[[tabController customizableViewControllers]objectAtIndex:1];//crashing here
充满了误解。
在[1]中,您将destinationViewController(类型UIViewController
)分配给类型为UITabBarController
的对象。这是编译器合法的(UITabBarController
继承自UIViewController
,因此它们都是UIViewController
类型),但它并不能真正反映出发生了什么。您的segue将转到UIViewController
或UINavigationController
。
因此,在第[2]行中,当您尝试使用将tabController作为标签栏控制器时,它会崩溃(因为它不是一个)。
您需要重新设计项目...忘记Segue,并使用标签栏控制器。有点像...
- (IBAction)moveToTab2:(id)sender {
ResultsViewController* resultsVC = (ResultsViewController*)
[[self.tabBarController viewControllers] objectAtIndex:1];
resultsVC.resultsArray=
[NSMutableArray arrayWithArray:_matchedResultsArray];
[self.tabBarController setSelectedViewController:resultsVC;
}