如何将数据从viewcontroller传递到tabbarcontroller到navaigationcontroller?

用户名

嗨,我是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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

将数据从 ViewController 传递到 TabBarController

ios将数据从TabbarController传递到Storyboard中的ViewController

如何将数据从viewController传递到swiftUI视图?

didSet之后如何将数据从AppDelegate传递到ViewController?

如何将模型数据从ViewController传递到ViewModel

如何将数据从API调用传递到ViewController?

如何将数据从 ViewController 传递到标签栏 iOS 中的 ViewController?

如何将数据从 ViewController3 传递到 ViewController1

将数据传递到TabBarController

Swift / iOS:如何将数据从 AppDelegate 传递到 ViewController 标签?

如何将数据从可解码模型传递或实现到 ViewController?

如何将数据从ViewController传递到嵌入式View Controller

如何将数据传递到ViewController并加载,然后再将其推入Navigation堆栈?

如何将参数从appDelegate传递到ViewController?

如何使用 NavigationController 将数据从 UIPickerView 传递到以前的 ViewController

将数据从 ViewController 传递到 View 时如何设置委托?

将数据从MyScene传递到ViewController?

将数据从ViewController传递到UITableViewController

将数据从TableViewCell标签传递到ViewController

Swift-如何从ViewController选择到TabBarController

如何将数据传递到选定的场景

NUXT如何将数据从页面传递到布局

如何将数据从.qml页传递到.qml页?

如何将数据传递到类之外的组件

如何将数据传递到fancybox函数?

如何将数据从父页面传递到弹出窗口?

如何将数据传递到嵌套布局

您如何将数据从Objective C传递到Swift?

如何将数据传递到SectionList?