嗨,我是iPhone开发的新手,正在使用情节提要执行我的项目,在我的项目中,我具有登录viewController,如果登录成功,它将转到tabbarcontroller。在tabbarController中,它具有三个viewControllers。在tabbarController和三个视图控制器之间,我有一个导航控制器。现在的问题是我必须将数据从loginviewController传递到tabBarcontroller到navigationController。我不知道该怎么办,请帮我。。?谢谢我事先使用此代码将数据从登录控制器传递到了tabbarcontroller
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSString * segueIdentifier = [segue identifier];
if([segueIdentifier isEqualToString:@"dashboard"]){
EventdashViewController *dc = [[EventdashViewController alloc] init];
FeedDashViewController *fc = [[FeedDashViewController alloc]init];
NewsDashViewController *nc = [[NewsDashViewController alloc]init];
UITabBarController* tbc = [segue destinationViewController];
dc = (EventdashViewController *)[[tbc customizableViewControllers] objectAtIndex:0];
dc.memberid = userid1;
NSLog(@"%d",dc.memberid);
fc = (FeedDashViewController *) [[tbc customizableViewControllers]objectAtIndex:1];
fc.memberid=userid1;
NSLog(@"%d",fc.memberid);
nc = (NewsDashViewController *)[[tbc customizableViewControllers]objectAtIndex:2];
nc.memberid = userid1;
NSLog(@"%d",nc.memberid);
}
}
如何将数据从ViewController传递到TabbarController到NavigationController?
首先,您要执行的操作似乎是将数据传递给导航控制器(dc,fc和nc)的根视图控制器,而不是导航控制器。问题在于,customizableViewControllers将返回导航控制器,而不是其根视图控制器。另外,您在alloc init中使用的三行代码是错误的,而且无论如何都是无用的,因为您重新定义了dc,fc和nc几行后的内容-如果已在情节提要中设置了所有内容,则标签栏控制器的标签栏控制器处于启用状态时,所有内容控制器都将实例化。您应该拥有的是:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSString * segueIdentifier = [segue identifier];
if([segueIdentifier isEqualToString:@"dashboard"]){
UITabBarController* tbc = [segue destinationViewController];
dc = (EventdashViewController *)[(UINavigationController *)tbc.viewControllers[0] topViewController];
dc.memberid = userid1;
NSLog(@"%d",dc.memberid);
fc = (FeedDashViewController *) [(UINavigationController *)tbc.viewControllers[1] topViewController];
fc.memberid=userid1;
NSLog(@"%d",fc.memberid);
nc = (NewsDashViewController *)[(UINavigationController *)tbc.viewControllers[2] topViewController];
nc.memberid = userid1;
NSLog(@"%d",nc.memberid);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句