簡體   English   中英

如何將數據從viewcontroller傳遞到tabbarcontroller到navaigationcontroller?

[英]How to pass data from viewcontroller to tabbarcontroller to 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);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM