我在使用模型 segue 打开标签栏 Controller 的标签栏 Controller 之前有一页(比如 X)。标签栏 Controller 的第一屏也与 X 相同。
I want to pass data from X to tab bar controller's first page.
不久,我想将数据从 View Controller 传递到带有 Storyboard segue 的选项卡栏 Controller 页面。有什么方法吗?
这是解决方案;
locationsHome* vc = [[locationsHome alloc] init];
UITabBarController* tbc = [segue destinationViewController];
vc = (locationsHome *)[[tbc customizableViewControllers] objectAtIndex:0];
最佳答案
这就是我解决问题的方法。您可以使用此方法将数据从 ViewController 传递到 TabBarController。
在 prepareForSegue
方法中使用此代码
locationsHome* vc = [[locationsHome alloc] init];
UITabBarController* tbc = [segue destinationViewController];
vc = (locationsHome *)[[tbc customizableViewControllers] objectAtIndex:0];
像这样:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSString * segueIdentifier = [segue identifier];
if([segueIdentifier isEqualToString:@"tabbarGo"]){
locationsHome* vc = [[locationsHome alloc] init];
UITabBarController* tbc = [segue destinationViewController];
vc = (locationsHome *)[[tbc customizableViewControllers] objectAtIndex:0];
etc...
}
}
关于ios - Storyboard使用 segue 将数据从 View Controller 传递到选项卡栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12652334/