Search code examples
objective-cuiviewcontrolleruitabbar

How can i pass value from ViewController to tabbar and then tabor to ViewController to the first selected item in tabbar


How can i pass value from ViewController to tabbar and then tabor to ViewController to the first selected item in tabbar which is selected from start

in first ViewController

tabBarViewController* infoController = [self.storyboard instantiateViewControllerWithIdentifier:@"tabBarViewController"];
    infoController.adView = adView;
    [self.navigationController pushViewController:infoController animated:YES];

in tabbar view controller:

 UIViewController *destView = [[self.tabBarController.viewControllers objectAtIndex:0] topViewController];
    NSLog(@"%@", destView);

Solution

  • UIViewController *destView = [[self viewControllers] objectAtIndex:0];
        NSLog(@"%@", destView);
        if ([destView isKindOfClass:[vc class]])
        {
            vc *destinationViewController = (vc *)destView;
            destinationViewController.adView = self.adView;
        }