如何通过Tab栏控制器传递数据viewcontroller

Nor*_*awa 12 uitabbarcontroller

我想通过标签栏控制器将数据从视图控制器传递到视图控制器.

我的意思是,我的故事板是这样的.

View Controller ? Tab Bar Controller ? VC1/VC2/VC3
Run Code Online (Sandbox Code Playgroud)

出于这个目的,我尝试使用PrepareforSegue,但它失败了.
代码在这里.

(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
friendsDetailViewController* vc = [[friendsDetailViewController alloc] init];
vc = (friendsDetailViewController*)[segue destinationViewController];

vc.candidateid = [[NSString alloc] init];
vc.candidateid = [candidateid objectAtIndex:selectedIndexPath.row];
Run Code Online (Sandbox Code Playgroud)

虽然我试图将数据从VC传递到VC1,但SIGABT发生在最后一行.


更新:

我已经弄明白了.这是脚本:

friendsDetailViewController* vc = [[friendsDetailViewController alloc] init];
UITabBarController* tbc = [segue destinationViewController];
vc = (friendsDetailViewController*)[[tbc customizableViewControllers] objectAtIndex:0];
Run Code Online (Sandbox Code Playgroud)

首先,我必须附上Tab Bar Controller.
其次,检索每个View Controller的指针.
您可以使用objectIndex进行选择.

Shu*_*Ali 0

在选项卡栏控制器的子视图控制器中,您可以使用以下方式轻松传递数据

[self.parentViewController.view setAccessibilityValue:@"your data"];
Run Code Online (Sandbox Code Playgroud)

并且可以轻松地在选项卡栏的其他子视图控制器中访问这些数据

或者您可以在 nsuserdefaults 中为某个键添加一个对象,并将该键附加到parentviewcontroller.view 中。通过在下一个视图控制器中使用 nsuserdefaults 中的 objectforkey 获取该对象